ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add value to the content of a cell with Vlookup (https://www.excelbanter.com/excel-programming/443580-add-value-content-cell-vlookup.html)

Nicawette

Add value to the content of a cell with Vlookup
 
Hi I have this piece of code add to the content of the cell selected a
figure that I will find with a vlookup function into another
spreadsheet (book1), but it cause an error?

can you help?

Sub update_figures()
Dim Q1_bill As Integer
Dim Total As Integer
Dim rng As Range

Set rng = Workbooks("Book1").Sheets("Pivot").Range("A6:U215" )

For i = 2 To 200

Q1_bill = ActiveSheet.Range("u" & i).Value

Total = Q1_bill + Application.VLookup("b" & i, rng, 19, False)

ActiveSheet.Range("u" & i).Select = Total

Next i

End Sub

Don Guillett Excel MVP

Add value to the content of a cell with Vlookup
 
On Sep 1, 9:56*am, Nicawette wrote:
Hi I have this piece of code add to the content of the cell selected a
figure that I will find with a vlookup function into another
spreadsheet (book1), but it cause an error?

can you help?

Sub update_figures()
Dim Q1_bill As Integer
Dim Total As Integer
Dim rng As Range

Set rng = Workbooks("Book1").Sheets("Pivot").Range("A6:U215" )

For i = 2 To 200

Q1_bill = ActiveSheet.Range("u" & i).Value

Total = Q1_bill + Application.VLookup("b" & i, rng, 19, False)

ActiveSheet.Range("u" & i).Select = Total

Next i

End Sub


Several errors.
Fully specify the workbook with .xls
Use proper syntax for the vlookup
'=====
option explicit
Sub lookupmacro()' Modify to suit
Dim rng As Range
Dim i As Long
Set rng = Workbooks("20100801.xls").Sheets("Sheet9").Range(" A6:U215")

For i = 2 To 5
Cells(i, "u") = Application.VLookup(Cells(i, "b"), rng, 19, 0)
Next i
End Sub
'======

Nicawette

Add value to the content of a cell with Vlookup
 
thank you Don


All times are GMT +1. The time now is 10:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com