samjones833
New Member
- Joined
- Nov 3, 2022
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
Hi all i currently have some code that copies data from one worksheet and pastes it into another, one column at a time. I'd like the code to loop and every time the loop occurs move to the next column to the right, however the loop would need to stop if the month name in row 4 does not match =TEXT(EOMONTH(TODAY(),0),"MMM"). My code looks up an item in a seperate spreadsheet which relates to the program number in cells B6:10, it then filters the spreadsheet and copies the data into column AH. It then repeats this process for all the other programs. Finally, for everytime the code passes through the loop the code would aslo need to change the cell if is copying the data from. Hope you can help and please ask any questions.
VBA Code:
Sub Update()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets("Gross X").Activate
'Remove autofilter
Columns("A:AN").Select
Selection.AutoFilter
'Add new Sheet
Sheets.Add.Name = "New Sheet"
'Return to Gross X, select 100% fit item and paste into New Sheet for L461
Sheets("Gross X").Activate
ActiveSheet.Range("A:AN").AutoFilter Field:=1, Criteria1:= _
"XYZ"
Cells.Select
Selection.Copy
Sheets("New Sheet").Select
Range("A1").Select
ActiveSheet.Paste
'Copy Dmd and paste into Data sheet
Sheets("New Sheet").Activate
Range("J2").Select
Selection.Copy
Sheets("Data").Activate
Range("B6").Activate
ActiveCell.End(xlToRight).Offset(0, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Delete sheets and provide msg box
Sheets("New Sheet").Delete
Sheets("Gross X").Activate
ActiveSheet.ShowAllData
Sheets("Data").Activate
Range("AG2").Select
Application.ScreenUpdating = True
MsgBox ("Update Complete")
End Sub