my VBA Vlookup function pasting number instead of the original text

cceze

New Member
Joined
Apr 20, 2018
Messages
8
I need help (first timer!).

I have a little vlookup VBA to paste a text but it keeps pasting a number.

(Application.WorksheetFunction.VLookup(Range("C1").Offset(i, 0), Sheets("example").Range("A:I"), 5, 0)


example -- C1 has the lookup 4000 and the column 5 has a text 044356

the vlookup displays 44,356

any help will be appreciated
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Welcome to the Board!

column 5 has a text 044356
Are you sure it is really text, and not a number with a custom format?
I suggest checking to see how column I is formatted.
 
Upvote 0
I tried to do a text to column conversion manually but when i run the macros, it still give me the number. Is there a way to change the custom format through VBA?
 
Upvote 0
Did you do what I asked?
Is column I a number with a Custom format?

If it is, and you want the value you are bringing back to be formatted in the same manner, then you will either need to apply the same custom format to the cell returning the value, or change the result to text with the custom format right in the formula (using TEXT function in Excel formula, or using FORMAT function in VBA).
 
Upvote 0
VLOOKUP only returns value, not formatting.

If you remove the formatting from column I, you will see that the value really is 44356.

If you have trouble applying the solutions mentioned in my previous post and need help applying it, please post the whole relevant block of VBA code (and not just the one line).
 
Upvote 0
here is the VBA. I really appreciate the help. been trying it all yesterday

Sub text()


Sheets("Sheet1").Range("b1").Offset(1, 0) = Application.WorksheetFunction.VLookup(Range("a1").Offset(1, 0), Sheets("Sheet2").Range("A:E"), 5, 0)


End Sub
 
Upvote 0
Let's just apply the same Custom formatting to the cell we are pasting to as in the cell we are pulling the information from:
Code:
[COLOR=#333333]Sub text()[/COLOR]

[COLOR=#333333]    Sheets("Sheet1").Range("b1").Offset(1, 0) = Application.WorksheetFunction.VLookup(Range("a1").Offset(1, 0), Sheets("Sheet2").Range("A:E"), 5, 0)[/COLOR]
[COLOR=#333333]    Sheets("Sheet1").Range("b1").Offset(1, 0)[/COLOR].NumberFormat = "000000"

[COLOR=#333333]End Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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