Storing Numbers as Text VBA

doubles011

New Member
Joined
Jul 21, 2015
Messages
1
I am trying to write a macro that I will use to insert vlookups into a number of different workbooks. The problem I am having is that the lookup array is composed of numbers stored as text in the source material, while the lookup values are stored as "general" in the workbooks in which I am inserting the vlookups. I tried just changing the lookup array to general, but it eliminates leading 0s that i need to keep. I also tried changing the lookup values to text, but this required me to go through and double click each cell so that the number would actually be stored as text. I then tried writing some code that would insert a column, change the number format to text in the blank column and then copy the lookup values and paste values in the new text column -- but that did not work either (using code below). Does anyone have any suggestions about how i can get these lookup values to be text without going through and individually selecting them all? Thanks

Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

Selection.NumberFormat = "@"

Columns("D:D").Copy

Columns("E:E").PasteSpecial Paste:=xlPasteValues
 
doubles011,

Welcome to Mr Excel.

Does it help if you modify your VLOOKUP formulas along these lines?
Assumes your numbers are 6 digits with leading zeros.


Excel 2007
ABCDEF
1234d000234d
2123456e001234a
39998f009998f
4026353b
5123456e
6237251c
Sheet1
Cell Formulas
RangeFormula
B1=VLOOKUP(TEXT(A1,"000000"),$E$1:$F$6,2)


Hope that helps.
 
Upvote 0

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