vba - vlookup value to be checked - String vs Long (or Integer) -



i trying read in value through vlookup , convert value via lookup table , must able read in both numbers , letters.

below code...

dim myvlookupresult string dim myrange range dim value string dim value1 long  value = "30"            ' works if there character in string value1 = 30             ' because long, can't have characters  worksheets("vlookup")      set myrange = .range(.cells(2, 3), .cells(257, 9))  end  myvlookupresult = worksheetfunction.vlookup(value, myrange, 7, false) msgbox myvlookupresult 

now part can't figure out following , appreciate help...

if place variable 'value' of type string command .vlookup(value, myrange,7, false), don't error long character in string. if value numbers, error of 1004.

i need able read / support both numbers , letters input argument used lookup value in vlookup command. since designating value type string, why fail if enter 30 example? string not string in vba.

again appreciated!

it contingent on lookup range is.

if the lookup range text looks numbers need use string.

if lookup range numbers need use number. need match.

if lookup range has both need 2 vlookups , deal error.

dim myvlookupresult variant dim myrange range dim value string dim value1 long  value = "30"            ' works if there character in string value1 = 30             ' because long, can't have characters  worksheets("vlookup")      set myrange = .range(.cells(2, 3), .cells(257, 9))  end   myvlookupresult = application.vlookup(value, myrange, 7, false) if iserror(myvlookupresult) myvlookupresult = application.vlookup(value1, myrange, 7, false) if iserror(myvlookupresult)     msgbox "value not found number or string" else     msgbox myvlookupresult end if 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -