Need offset range for loop
If you want to look in column F of Scroller Info for your cells that are
greater than 50 and copy the row of any such cell to Spare Scroller Cables
starting in A2 and working down, then:
Sub DefineBundles()
Dim cell As Range, rng As Range
Dim j As Long
With Sheets("Scroller Info")
Set rng = .Range(.Range("F2"), .Range("F2").End(xlDown))
End With
j = 0
For Each cell In rng
If cell.Value = 50 Then
CreateSpare cell, j
j = j + 1
End If
Next
End Sub
Sub CreateSpare(cell1 As Range, Offst As Long)
Dim DestRange As Range
Set DestRange = Worksheets("Spare Scroller Cables").Range("A2")
cell1.EntireRow.Copy Destination:=DestRange.Offset(Offst,0)
End Sub
--
Regards,
Tom Ogilvy
"Joe Fish" wrote in message
ups.com...
Tom,
I figured out what I was doing wrong, I was changing the name of the
macro so it wouldn't conflict with the old one, but I forgot to change
the name of the internal run command. Ok, I fixed that, then I got the
sub to run, but it didn't do anything because the destination and
source ranges were reversed.
So I edited the ranges in the code, and then I got "Run Time Error
1004: Application-defined or object-defined error" and this was
highlighted:
cell1.EntireRow.Copy Destination:=DestRange.Offset(Offst, -5)
Here's what I did post-editing:
Sub DefineBundles()
Dim cell As Range, rng As Range
Dim j As Long
With Sheets("Scroller Info")
Set rng = .Range(.Range("A2"), .Range("F2").End(xlDown))
End With
j = 0
For Each cell In rng
If cell.Value = 50 Then
CreateSpare cell, j
j = j + 1
End If
Next
End Sub
Sub CreateSpare(cell1 As Range, Offst As Long)
Dim DestRange As Range
Set DestRange = Worksheets("Spare Scroller Cables").Range("A2")
cell1.EntireRow.Copy Destination:=DestRange.Offset(Offst, -5)
End Sub
I have learned a ton with every go, thanks for the help, man.
Joe
|