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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,344
Office Version
  1. 365
Platform
  1. Windows
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
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
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
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
On Sheet2, Cell: A2 add this formula:

="DL" & Sheet1!A2

Then copy this formula down to the bottom of your range on Sheet2!
 

bongyc

New Member
Joined
Nov 1, 2005
Messages
18

ADVERTISEMENT

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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,344
Office Version
  1. 365
Platform
  1. Windows
Chr(34) represents a double quote ", which is needed for the worksheet formula.
 

bongyc

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

Thanks for the explanation. It helps me to understand better.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,023
Messages
5,834,996
Members
430,331
Latest member
Syed Yasir Hannan

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
Top