Hello,
Please help me from going totally insane! I'm not hugely experienced with Excel and have no idea about VLookups, Macros or VBA but I've been hunting for the answer to my problem for hours and hours with no success!!
I have a spreadsheet for our small building company where I want to keep track of all our purchases but also be able to detail what's been bought for each separate job that we're doing as we have a few sites on the go at once. I have one workbook with several sheets on it. Sheet 1 is "Total Purchases" which is where I'll enter the data and each separate job has it's own named sheet within the workbook. eg - sheet 2 is: "Anvil Cottage 001" , sheet 3 is "35 The Leys 002" , sheet 4 is "PFB 003" etc. The incremented numbers 001, 002, 003 are our job reference number which is used to identify them on the "Total Purchases" sheet in column E.
From trawling through this site, and many others, I've found and tried to adapt a Macro that will look down column E on the "Total Purchases" sheet and wherever it finds "001" it then copies that entire row to the "Anvil Cottage 001" sheet. When it finds "002" in column E it copies that entire row to "35 The Leys 002" sheet and so on. Hopefully this makes sense.
What doesn't seem to work is the Macro that I've tried to use. I've only done it for the "Anvil Cottage 001" sheet so far, and I'm sure I'll have to use a similar Macro on each sheet (with the corresponding details in the macro for each different job name) but this first one is not working. This is the Macro I've got:
Sub CopyRow()
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Sheets("Total Purchases").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim x As Long
x = 3
Dim rng As Range
For Each rng In Sheets("Total Purchases").Range("E3:E" & LastRow)
If rng = "001" Then
rng.EntireRow.Copy
Sheets("Anvil Cottage 001").Cells(x, 1).PasteSpecial xlPasteValues
x = x + 1
End If
Next rng
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Where is it going wrong?! I'm using Excel for Mac 2016 (Version 16.16.3) if that makes much difference.
Thank you so much.
ray:
Please help me from going totally insane! I'm not hugely experienced with Excel and have no idea about VLookups, Macros or VBA but I've been hunting for the answer to my problem for hours and hours with no success!!
I have a spreadsheet for our small building company where I want to keep track of all our purchases but also be able to detail what's been bought for each separate job that we're doing as we have a few sites on the go at once. I have one workbook with several sheets on it. Sheet 1 is "Total Purchases" which is where I'll enter the data and each separate job has it's own named sheet within the workbook. eg - sheet 2 is: "Anvil Cottage 001" , sheet 3 is "35 The Leys 002" , sheet 4 is "PFB 003" etc. The incremented numbers 001, 002, 003 are our job reference number which is used to identify them on the "Total Purchases" sheet in column E.
From trawling through this site, and many others, I've found and tried to adapt a Macro that will look down column E on the "Total Purchases" sheet and wherever it finds "001" it then copies that entire row to the "Anvil Cottage 001" sheet. When it finds "002" in column E it copies that entire row to "35 The Leys 002" sheet and so on. Hopefully this makes sense.
What doesn't seem to work is the Macro that I've tried to use. I've only done it for the "Anvil Cottage 001" sheet so far, and I'm sure I'll have to use a similar Macro on each sheet (with the corresponding details in the macro for each different job name) but this first one is not working. This is the Macro I've got:
Sub CopyRow()
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Sheets("Total Purchases").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim x As Long
x = 3
Dim rng As Range
For Each rng In Sheets("Total Purchases").Range("E3:E" & LastRow)
If rng = "001" Then
rng.EntireRow.Copy
Sheets("Anvil Cottage 001").Cells(x, 1).PasteSpecial xlPasteValues
x = x + 1
End If
Next rng
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Where is it going wrong?! I'm using Excel for Mac 2016 (Version 16.16.3) if that makes much difference.
Thank you so much.
ray: