treat numbers as text

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,550
The following code is not working:

Code:
 If Application.WorksheetFunction.VLookup(subj, sheet.Range("d1:f1048576"), 3, 0) = "indefinable" Then

I know the problem has to be because the subj is a number but I'm trying to treat it as a string. I've reformatted the cells as both text and general but that still does not work. The macro works on every other object in the d column except for those objects which are numbers. I have even tried the following code

If isnumeral(subj) Then
subj = CStr(subj)
End If

But that doesn't work either. The error message I'm getting is 1004.
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,647
have you tried:
Code:
 If Application.WorksheetFunction.VLookup(format(subj, "@"), sheet.Range("d1:f1048576"), 3, 0) = "indefinable" Then
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Perhaps

If Application.WorksheetFunction.VLookup(subj & "", sheet.Range("d1:f1048576"), 3, 0) = "indefinable" Then
 

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,550

ADVERTISEMENT

Ok, I looked at some of my old drafts because I used to be able to do this and I noticed that in my old drafts I have that green triangle in the corner for the numbers. If I could get that green triangle back that might help things.
 

PKFillmore

New Member
Joined
Apr 3, 2012
Messages
24
1006 error is usually caused when It can't find the data (#N/A) values in worksheet....
vlookups in vba are tricky, this is one way to get rid of the error of when the vlookup finds nothing...


Code:
subj = 2    
    On Error Resume Next
        x = Application.WorksheetFunction.VLookup(subj, Range("D1:F1048576"), 3, 0)
    
        If Err <> 0 Then
            x = "Not Found"
        End If
        
    On Error GoTo 0


    If x = "indefinable" Then
       'Your Code Here
    End If

But you would still need to convert your data to text for it to work the best.
I have found that the best way to convert data to text is to use Text to Columns to convert,
here is a tidbit of code I sometimes use to do that...
Code:
    For x = 4 To 6  '-> Column Number
    
        Columns(x).Select
        Selection.TextToColumns Destination:=Range(Selection.Address), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 2), TrailingMinusNumbers:=True
    
    Next x
 

Watch MrExcel Video

Forum statistics

Threads
1,122,519
Messages
5,596,635
Members
414,083
Latest member
Mrsash

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