VBA vlookup rounding issue

cmefly

Well-known Member
Joined
May 13, 2003
Messages
683
hi,

i've got a code that works. The vlookup is working but retrieving a rounded version of the number its suppose to retrieve. why is it rounding it for me??

Code:

Sub Macro1()

Dim a, charge As String
Dim b As Integer
Dim k As Range
Dim i, j As Integer
Dim l As Long


Windows("whatsnew.xls").Activate
Sheets("Sheet1").Select
a = Range("B1").Value


Windows("whatsnew.xls").Activate

For Each k In Range("a1:a100")

If k.Value = a Then
b = k.Row
End If

If b > 0 Then
Exit For
End If

Next k

'Range("B10").Value = b

Windows("whatsnew.xls").Activate
Range("a1").Select

For i = 2 To 68

Cells(2, i).Select

charge = Cells(2, i).Value

Cells(b, i).Select

j = Application.VLookup(charge, Workbooks("filename.xls").Sheets("Sheet1").Range("A3:e70"), 4, False)

Cells(b, i).Value = j

Next i

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"
You've declared j as an Integer, which only contain whole numbers. Declare it as a Double.

Incidently, you've declared i, by default, as a Variant. You need to specify the data type for each variable.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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