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
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,782
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,158
Messages
5,600,054
Members
414,357
Latest member
Gemma_R

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