Ganesh Thiruvengadam
Ganesh Thiruvengadam

Reputation: 41

MS EXCEL MACRO: Add a prefix and suffix to an entire column of cells?

Data is in Column F.
I need to add .com/ to the beginning of the word in the cells.
Then add .JPG to the very end of every word in the cells.

In other words:
189389439
Needs to end up as:
.com/189389439.JPG

Upvotes: 1

Views: 5356

Answers (3)

Ganesh Thiruvengadam
Ganesh Thiruvengadam

Reputation: 41

Figured it out myself:

Sub JPegMe()
    Dim myCell As Range
    For Each myCell In Selection
        If Not IsEmpty(myCell) Then _
            myCell = ".com\" & myCell & ".JPG"
    Next myCell
End Sub 

Upvotes: 1

pablo.vix
pablo.vix

Reputation: 2233

I would set on cell G1 the formula ' =".com/" & F1 & ".jpg" ' and then expand this formula to all other rows by double clicking in the right down square that appear if you select the G1 cell.

Upvotes: 0

Simon1979
Simon1979

Reputation: 2108

Does this need to be VBA?

If you just put the formula in G1 (assuming no column header, or it would be in G2):

=".com/" & F1 & ".JPG"

And copy this down then you will get what you need and then you can just paste special to save the values (if you need to), potentially over the original data and then delete your column G.

Upvotes: 0

Related Questions