I want to make a vba function that looks for a value from a range in sheet "Data", and looks for all the values in column A of that sheet in all of the following sheets. if a match is found, a summary sheet will be created, and it will contain all the values found and the accumulated addition of the numeric values in column B of the matches in all of the sheets.
This is what I have so far, but its giving me an error, and I don't know how to fix it.
Any help will be greatly appreciated.
Thanks.
This is what I have so far, but its giving me an error, and I don't know how to fix it.
Any help will be greatly appreciated.
Thanks.
Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Dim ws As Worksheet
Dim strWhat As String
Dim rngSearch, rng As Range
Dim rngFound As String
Dim i As Integer
Set rng = Range("A2:A1048576")[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]For Each cell In rng
value = 0
cantidad = 0
precio = 0
unidad = cell
For Each ws In ActiveWorkbook.Worksheets
Set rngSearch = ws.Cells.Find(What:=cell.value)
cantidad1 = Application.VLookup(cell, ws.Range("A2:A1048576"), 2, False)
cantidad = cantidad
If Not rngSearch Is Nothing Then
i = i + 1
If i = 1 Then
rngFound = rngSearch.Worksheet.Name
Else
rngFound = rngFound & ", " & rngSearch.Worksheet.Name
End If
precio = precio + Application.WorksheetFunction.VLookup(cell, ws.Range("A2:A1048576"), 3, False)
valor = valor + Application.WorksheetFunction.VLookup(cell, ws.Range("A2:A1048576"), 4, False)
' Insert your code here.
' The following line shows how to reference a sheet within
' the loop by displaying the worksheet name in a dialog box.
Next ws
Next cell[/FONT]