aussiegrl14
New Member
- Joined
- Jun 23, 2009
- Messages
- 3
I'm trying to make a macro to look for an "x" in a certain column, indicating the information should be duplicated from a different line, and then to copy and paste that information from the original into the duplicate line.
I have several instances of these duplicates so I want it to finish copying and pasting one duplicate, then continue to the next one. Here is the code:
However every time I try to run it I get a Run-time error '91': "Object variable or With block variable not set". It hits the error on the bold line.
Can anyone see what I did wrong? I'd appreciate any help you can give me.
Thanks!
I have several instances of these duplicates so I want it to finish copying and pasting one duplicate, then continue to the next one. Here is the code:
Rich (BB code):
With Range("F5:F500")
Set f = .Find("x", LookIn:=xlValues, Lookat:=xlWhole) 'Finds a line designated as a "child"
firstaddress = f.Address
Do
f.Activate
desc = ActiveCell.Offset(0, -2)
With Range("D5:D500")
Set d = .Find(desc, LookIn:=xlValues, Lookat:=xlWhole) 'Look for "parent" line with same description
secondaddress = d.Address
Do
d.Activate
If ActiveCell.Offset(0, 2) = "x" Then 'Make sure the line is a "parent" before copying
Set d = .FindNext(d) 'Copies info from column I to W
Else
ActiveCell.Offset(0, 6).Select
Range(ActiveCell, ActiveCell.Offset(0, 14)).Copy
Set d = .FindNext(d)
End If
Loop While Not d Is Nothing And d.Address <> secondaddress
End With
With Range("D5:D500")
Set e = .Find(desc, LookIn:=xlValues, Lookat:=xlWhole) 'Look for the "child" lines
thirdaddress = e.Address
Do
e.Activate
If ActiveCell.Offset(0, 2) <> "x" Then 'Confirm the line is a "child" before pasting
Set e = .FindNext(e)
Else
ActiveCell.Offset(0, 6).Select
Range(ActiveCell, ActiveCell.Offset(0, 14)).PasteSpecial (xlPasteAll)
Set e = .FindNext(e)
End If
Loop While Not e Is Nothing And e.Address <> thirdaddress 'Find all "child" lines
End With
Set f = .FindNext(f)
Loop While Not f Is Nothing And f.Address <> firstaddress 'Find all entries in need of duplicating
End With
However every time I try to run it I get a Run-time error '91': "Object variable or With block variable not set". It hits the error on the bold line.
Can anyone see what I did wrong? I'd appreciate any help you can give me.
Thanks!