Macro To Add 'FA'

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
Is there a macro code I can run that will add 'FA' to the front of any value in a cell in column 'A'? I know I could use a helper column then concatenate etc but there are some blank cells etc and I thought if there is a code someone could give me I would be obliged. Thanks.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try

Code:
Sub AddFA()
With Columns("A").SpecialCells(xlConstants, xlTextValues)
    .Value = "FA" & .Value
End With
End Sub
 
Upvote 0
Thanks I get runtime 13 error though and it points to
.Value = "FA" & .Value

Not sure if it makes a difference but the values in "A" will be a combo of text and numbers.
 
Upvote 0
I can't reproduce that error but my previous code didn't function properly anyway. Try

Code:
Sub AddFA()
Dim c As Range
For Each c In Columns("A").SpecialCells(xlConstants, xlTextValues)
    c.Value = "FA" & c.Value
Next c
End Sub
 
Upvote 0
I can't reproduce that error but my previous code didn't function properly anyway. Try

Code:
Sub AddFA()
Dim c As Range
For Each c In Columns("A").SpecialCells(xlConstants, xlTextValues)
    c.Value = "FA" & c.Value
Next c
End Sub

Thanks VoG this works great but I was thinking...

I will use this quite a lot but with various letters rather than FA. Is there anyway the code can be adapted to when I highlight a column for example column C and run the macro a box would pop saying something like 'what letters would you like added' then i enter the letters, press ok, then the macro runs? Thanks.
 
Upvote 0
Try this

Code:
Sub AddOwt()
Dim c As Range, s As String
s = InputBox("Enter prefix")
If s = "" Then Exit Sub
For Each c In Selection.SpecialCells(xlConstants, xlTextValues)
    c.Value = s & c.Value
Next c
End Sub
 
Upvote 0
Thanks VoG, great stuff. Can you not help with my Mail Merge issue?
 
Upvote 0
Hi VoG,

As always a superbly simple solution, how would make the code work with numbers instead of text?
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top