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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,833
Office Version
  1. 2010
Platform
  1. Windows
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,710
Messages
5,833,247
Members
430,200
Latest member
ADLHMA2022

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