VBA Code to Convert to Number

Status
Not open for further replies.

Justinian

Well-known Member
Joined
Aug 9, 2009
Messages
1,557
Office Version
  1. 365
Platform
  1. Windows
How do I alter this code so the results of the VLOOKUP and RIGHT formulas are converted from text to number?

Sub VLOOKUP()
Dim LastRw As Long
LastRw = Cells(Rows.Count, "A").End(xlUp).Row

' Run VLOOKUP formula starting in B6
With Range("B6")
.FormulaR1C1 = _
"=IFERROR(IF(OR(LEFT(RC[-1],1)=""9"",LEFT(RC[-1],2)<=""32""),VLOOKUP(RC[-1],Gardens,2,FALSE),RC[-1]),"""")"
.AutoFill Destination:=Range("B6:B" & LastRw)
End With

' Applies RIGHT formula to column I and pastes resulting values into column A
With Range("I6:I" & Range("A" & Rows.Count).End(xlUp).Row)
.FormulaR1C1 = "=RIGHT(RC[-8],LEN(RC[-8])-FIND(""-"",RC[-8],1))"
.Copy
Range("A6").PasteSpecial xlPasteValues
.ClearContents
End With

ActiveSheet.PageSetup.PrintArea = Range("A4").CurrentRegion.Address

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Just put +0 at the end of the formula.
 
Upvote 0
Do they both return numbers stored as text?
 
Upvote 0
Yes I know, but does the vlookup also return numbers stored as text?
 
Upvote 0
In that case just add it to the right formula
 
Upvote 0
I did that and it worked for numbers stored as text but it screwed up the VLOOKUP results on cells that were formatted as numbers.
 
Upvote 0
All your data should be of the same type, either text or numbers, if you have a mix you are asking for problems.
I would suggest you sort out your data.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,361
Messages
6,124,497
Members
449,166
Latest member
hokjock

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