Hey,
I'm looking for some help editing this macro, it's fairly hard to explain but should be fairly easy to change/fix I hope.
Basically, I need the macro instead of copying from first row(s) it finds for it to copy from 3 rows down from the first row it finds (offset of 3) but when it's retreiving the data back it needs to put it back in it's original place so it needs to detect the fact it's left 3 rows of data out when it copies...
Function COPYDATA(ByVal varFind As Variant, ByVal wsDest As Worksheet)
Dim rngCopy As Range
Dim rngFound As Range
Dim strFirst As String
Dim lRow As Long
With Sheets("Sheet1").Columns("A")
Set rngFound = .Find(varFind, .Cells(.Cells.Count), xlValues, xlWhole)
If Not rngFound Is Nothing Then
strFirst = rngFound.Address
Set rngCopy = rngFound.CurrentRegion.Resize(rngFound.CurrentRegion.Rows.Count + 1).EntireRow
Do
Set rngCopy = Union(rngCopy, rngFound.CurrentRegion.Resize(rngFound.CurrentRegion.Rows.Count + 1).EntireRow)
Set rngFound = .Find(varFind, rngFound, xlValues, xlWhole)
Loop While rngFound.Address <> strFirst
lRow = WorksheetFunction.Max(wsDest.Cells(Rows.Count, "A").End(xlUp).Row + 2, 16)
rngCopy.Copy wsDest.Cells(lRow, "A")
Set rngFound = Nothing
Set rngCopy = Nothing
End If
End With
End Function
Function RETRIEVEDATA(ByVal varFind As Variant, ByVal wsSrc As Worksheet)
Dim rngDest As Range
Dim rngFound As Range
Dim strFirst As String
Set rngDest = Sheets("Sheet1").Columns("A").Find(varFind, Sheets("Sheet1").Cells(Rows.Count, "A"), xlValues, xlWhole)
Set rngFound = wsSrc.Columns("A").Find(varFind, wsSrc.Cells(Rows.Count, "A"), xlValues, xlWhole)
If Not rngFound Is Nothing Then
strFirst = rngFound.Address
Do
rngFound.CurrentRegion.EntireRow.Copy rngDest.Offset(-1)
Set rngFound = wsSrc.Columns("A").Find(varFind, rngFound, xlValues, xlWhole)
Set rngDest = Sheets("Sheet1").Columns("A").Find(varFind, rngDest, xlValues, xlWhole)
Loop While rngFound.Address <> strFirst
Set rngDest = Nothing
Set rngFound = Nothing
End If
End Function
Bookmarks