Add Text infront of Numbers

bongyc

New Member
Joined
Nov 1, 2005
Messages
18
Dear all,

In Sheet 1, A2 to A100 contains a list of numbers. I would like to do the following by creating a VBA:

1) Copy A2 to A100 from Sheet 1 to Sheet 2 at A2 to A100;

2) Add a text "DL" infront of the numbers in Sheet 2 after the above copying.

Appreciate for your expertise. Thank you.

Cheers,
YC
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Do you really need VBA?
Code:
Sub CopyAddDL()

    Worksheets("Sheet2").Range("A2").Formula = "=" & Chr(34) & "DL" & Chr(34) & "& Sheet1!A2"
    
    Worksheets("Sheet2").Range("A2").Copy Worksheets("Sheet2").Range("A2:A100")
    
    Worksheets("Sheet2").Range("A2:A100").Copy
    
    Worksheets("Sheet2").Range("A2").PasteSpecial xlPasteValues
    
    Application.CutCopyMode = False
    
End Sub
 
Upvote 0
Code:
Sub CopyData()
Dim cell as range, ss as worksheet, ps as worksheet

set ss = activesheet
set ps = sheets("Sheet2")

for each cell in ss.range("A2:A100")
  ps.range(cell.address) = "DL"& cell
Next 

End sub

HTH
Cal
 
Upvote 0
On Sheet2, Cell: A2 add this formula:

="DL" & Sheet1!A2

Then copy this formula down to the bottom of your range on Sheet2!
 
Upvote 0
Dear Joe, Cbrine and Norie,

Thank you very much with the brilliant solutions which really made my day.

Norie, may I know what is the reason for putting Chr(34) before and after DL in the VBA ?

Cheers,
YC
 
Upvote 0
Chr(34) represents a double quote ", which is needed for the worksheet formula.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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