johnandginalyn
New Member
- Joined
- Jun 14, 2010
- Messages
- 6
Hi,
I have a macro that works in the spreadsheet it was written in but when I try to run it in an identical spreadsheet outside of where the macro is stored then I get the 1004 error.
I understand that this is a reference issue with the sheets but I can get rid of an error in the formula line.
I'm getting the error on the line in red.
I really hope someone can shine a light on this.
Please help,
John
I have a macro that works in the spreadsheet it was written in but when I try to run it in an identical spreadsheet outside of where the macro is stored then I get the 1004 error.
I understand that this is a reference issue with the sheets but I can get rid of an error in the formula line.
Code:
Sub LookingUp()
Dim wks As Worksheet
Dim col As Integer
Dim colA As Integer
Dim colB As Integer
Dim rowA As Integer
Dim row As Integer
Dim ref As Range
Dim ts As String
rowA = 1
ActiveWorkbook.Sheets(1).Select
Cells.Find(What:="Asset Id", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
colB = ActiveCell.Column
colA = colB + 1
For Each wks In ActiveWorkbook.Worksheets
If Not wks.Name = "List_of_Assets" Then
wks.Select
Cells.Find(What:="Asset Id", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.End(xlDown).Select
row = ActiveCell.row
col = ActiveCell.Column
ActiveWorkbook.Sheets(1).Select
Cells(1, colA).Select
ActiveCell.EntireColumn.Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(1, colB).Select
Selection.End(xlDown).Select
rowA = ActiveCell.row
Cells(2, colA).Select
[COLOR=red]ActiveCell.Formula = "=VLOOKUP(" & Cells(2, colB).Address(False, False) & "," & wks.Name & "!" & Cells(2, col).Address & ":" & Cells(row, col).Address & ",1,0)"[/COLOR]
Selection.AutoFill Destination:=Range(ActiveCell, Cells(rowA, ActiveCell.Column))
colA = colA + 1
End If
Next wks
End Sub
I'm getting the error on the line in red.
I really hope someone can shine a light on this.
Please help,
John