how2 keep #stored as text as #stored as text in macro variab

theomountain

New Member
Joined
Jan 22, 2003
Messages
29
How do I keep the format of my variable value in a macro as number stored as text

locn = activecell.value (the active cell shows 0023, number stored as text)
The column is formatted as text
with the macro I go to another sheet (same workbook), select a cell and
activecell.value = locn (this active cell shows 23)
this column is formatted as text

how do I get the value to show 0023?

Is there a VBA command extension that will force the value to stay the same

Thanks
Theo
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try like this

Code:
Sub test()
Sheets("Sheet1").Range("A1").Copy
Sheets("Sheet2").Range("A1").PasteSpecial Paste:=xlValues
Sheets("Sheet2").Range("A1").PasteSpecial Paste:=xlFormats
End Sub
 
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,168,084
Messages
5,857,269
Members
431,867
Latest member
Dalorian

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