If you want an example of code that will work for this, you can upload a
workbook I quickly tossed together from:
http://www.jlathamsite.com/uploads/codebook_foraine.xls
If you just want to see the working code (which is dependent on layout and
sheet names used in the sample workbook), here it is. It presumes that no
list goes all the way to the end of a worksheet - doesn't trap for that
situation.
Sub GatherDataTogether()
Dim ToBeCompared As String
Dim ListSheet As String
Dim CollateSheet As String
Dim DataSheets(1 To 3) As String
Dim SecondDataSheet As String
Dim ThirdDataSheet As String
Dim ListRowOffset As Long
Dim DataOffsetRow As Long
Dim LC As Integer ' loop counter
'initialize to find our sheets later
ListSheet = "ListSheet"
CollateSheet = "GatheredSheet"
DataSheets(1) = "Sheet1"
DataSheets(2) = "Sheet2"
DataSheets(3) = "Sheet3"
'get ready
'activate the next instruction to speed things up
'Application.ScreenUpdating = False
Worksheets(CollateSheet).Activate
'choose place to move 1st match to
Range("A1").Select
Sheets(ListSheet).Activate
'choose first 'to match' entry
Range("A1").Select
Do Until IsEmpty(ActiveCell)
ToBeCompared = ActiveCell.Value
For LC = LBound(DataSheets) To UBound(DataSheets)
Worksheets(DataSheets(LC)).Activate
Range("A1").Select ' start of data
DataOffsetRow = 0 ' (re)initialize
Do Until IsEmpty(ActiveCell.Offset(DataOffsetRow, 0))
If ActiveCell.Offset(DataOffsetRow, 0) = ToBeCompared Then
DataOffsetRow = DataOffsetRow + 1
Rows(DataOffsetRow & ":" & DataOffsetRow).Copy
'move to destination sheet
Sheets(CollateSheet).Activate
'Rows(ActiveCell.Row & ":" & ActiveCell.Row).Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.Offset(1, 0).Activate ' prepare for next
'back to data sheet for more checking
Sheets(DataSheets(LC)).Activate
Range("A1").Select ' back to top of list
Else
DataOffsetRow = DataOffsetRow + 1
End If
Loop ' data on current data sheet
Next ' LC loop
Sheets(ListSheet).Activate
ActiveCell.Offset(1, 0).Activate ' move down 1 row
Loop ' lookup list
End Sub
"Aine" wrote:
That would be ideal.
Have a good background in programming & logic, but have never touched
macros
I normally work with databases but the company I am contracting for
want it all through excel for visibility purposes(plus they prefer us
not to use MS Access)
Do you know any good site with macros tutorials for these types of
queries?