scott-atkinson
I'm with the Witch.......
- Local time
- Today, 10:08
- Joined
- Aug 31, 2006
- Messages
- 1,622
Guys,
I hope you can help, my code is below;
I am trying to use a For Next routine within the same Procedure with an error trap. And I am getting an error message stating Next without For.
My code basically uses a For Next Loop to perform a copy and paste function but with two different criteria's, if criteria one is not met, then the error trap prompts another part of the routine to run to satisfy the alternative criteria, but I am trying to confine this within one For Next loop
I hope you can help, my code is below;
I am trying to use a For Next routine within the same Procedure with an error trap. And I am getting an error message stating Next without For.
My code basically uses a For Next Loop to perform a copy and paste function but with two different criteria's, if criteria one is not met, then the error trap prompts another part of the routine to run to satisfy the alternative criteria, but I am trying to confine this within one For Next loop
Code:
Application.ScreenUpdating = False
Dim MS As String, Fis As String, sku As Long
' Counts the number of Master Skus in range and applies to a Variable
Sheets("List").Select
Cells(1, 1).Select
Range(Selection, Selection.End(xlDown)).Select
sku = Selection.Count
Cells(1, 1).Select
MS = ActiveCell.Value
' Opens the Archive Workbook
Workbooks.Open Filename:= _
"I:\H914 Development and Supply Chain\AWR\FLM Archive\FLM Archive - Homewares.xlsx"
Cells(1, 1).Select
' Checks to see if the selected Master Sku exists in the Archive
For b = 1 To sku
Windows("AWR Forward Line Monitor - Homewares.xlsm").Activate
Range("B4").Select
ActiveCell.Value = MS
Windows("FLM Archive - Homewares.xlsx").Activate
On Error GoTo A ' If Master Sku is not in Archive then call the procedure to create the Archive Entry
Cells.Find(What:=MS, After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
On Error GoTo 0
' continues with routine once existing Master Sku is found
' reverts to Line Monitor to copy new data
Windows("AWR Forward Line Monitor - Homewares.xlsm").Activate
Cells(6, 3).Select
Fis = ActiveCell.Value ' assigns the first week of the Line Monitor to a variable
Windows("FLM Archive - Homewares.xlsx").Activate
' navigates to week variable on archive worksheet
Cells.Find(What:=Fis, After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
' reverts to Line Monitor and copies data table
Windows("AWR Forward Line Monitor - Homewares.xlsm").Activate
Range("C6:BB19").Select
Selection.Copy
' reverts to archive and pastes as values data table
Windows("FLM Archive - Homewares.xlsx").Activate
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
' saves anc closes archive
Cells(1, 1).Select
' reverts to Line Monitor
Windows("AWR Forward Line Monitor - Homewares.xlsm").Activate
Sheets("List").Select
Selection.Offset(1, 0).Select
MS = ActiveCell.Value
Next b
Application.ScreenUpdating = True
End
A:
Windows("FLM Archive - Homewares.xlsx").Activate
' selects the last cell in the worksheet
Cells(1048576, 1).Select
' brings the curser up to the next available entry, if none then to the top of the worksheet, and then offsets by one row
Selection.End(xlUp).Offset(2, 0).Select
' Puts the new Master Sku code into the valid cell
ActiveCell.Value = MS
Selection.Offset(1, 0).Select
' Reverts to Line Monitor to copy data
Windows("AWR Forward Line Monitor - Homewares.xlsm").Activate
' Copies titles
Range("A7:A19").Select
Selection.Copy
' Pastes titles inot archive
Windows("FLM Archive - Homewares.xlsx").Activate
ActiveSheet.Paste
Application.CutCopyMode = False
Columns("A:A").EntireColumn.AutoFit
' places active cell next to Master Sku cell to paste data
Selection.Offset(-1, 1).Select
' reverts to Line Monitor to copy data table
Windows("AWR Forward Line Monitor - Homewares.xlsm").Activate
Range("C6:BB19").Select
Selection.Copy
' reverts to archive and pastes data formats and values
Windows("FLM Archive - Homewares.xlsx").Activate
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
' saves and closes the archive
Cells(1, 1).Select
' reverts to Line Monitor
Windows("AWR Forward Line Monitor - Homewares.xlsm").Activate
Sheets("List").Select
Selection.Offset(1, 0).Select
MS = ActiveCell.Value
Next b
Application.ScreenUpdating = True
End Sub