Macro to Add Prefix or Suffix to Column

bohsi

New Member
Joined
Aug 26, 2012
Messages
1
Hi,

I recorded the following macro to add a thorn symbol before and after each record in a table. I can't figure out how to edit the macro so that it will work with a different set a data where there is a different amount of records. Help is much appreciated. Thanks.
Sub Macro6()


Range("A1:A26").Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$A$26"), , xlNo).Name = _
"Table9"
Range("Table9[#All,[Column1]]").Select
ActiveSheet.ListObjects("Table9").TableStyle = "TableStyleLight1"
Range("B1").Select
ActiveCell.FormulaR1C1 = "þ"
Range("C2").Select
ActiveCell.FormulaR1C1 = _
"=Table9[#Headers,[þ]]&[@Column1]&Table9[#Headers,[þ]]"
Range("C3").Select

End Sub>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I am not sure what you want to do but the below tested code duplicates your functionality while working with any number of contiguous cell in col. A (starting with A1).
Code:
Sub Macro6()
    Dim aLO As ListObject
    Set aLO = ActiveSheet.ListObjects.Add(xlSrcRange, _
        Range(Range("a1"), Range("a1").End(xlDown)), , xlNo)
    aLO.TableStyle = "TableStyleLight1"
    Range("B1").FormulaR1C1 = "þ"
    Range("C2").FormulaR1C1 = _
        "=" & aLO.Name & "[[#Headers],[þ]]&[@Column1]&" _
            & aLO.Name & "[[#Headers],[þ]]"
    End Sub
Hi,

I recorded the following macro to add a thorn symbol before and after each record in a table. I can't figure out how to edit the macro so that it will work with a different set a data where there is a different amount of records. Help is much appreciated. Thanks.
Sub Macro6()


Range("A1:A26").Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$A$26"), , xlNo).Name = _
"Table9"
Range("Table9[#All,[Column1]]").Select
ActiveSheet.ListObjects("Table9").TableStyle = "TableStyleLight1"
Range("B1").Select
ActiveCell.FormulaR1C1 = "þ"
Range("C2").Select
ActiveCell.FormulaR1C1 = _
"=Table9[#Headers,[þ]]&[@Column1]&Table9[#Headers,[þ]]"
Range("C3").Select

End Sub>
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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