Hi All,
I am strugling (rookie) with a loop. I think I have the ending of the loop wrong some how?
Currently the code selects the folder location then says 'CC Reports completed'.
As I am trying to test it, column A has data 4-100 rows long. Column I has data 4-19 with 4 showing true the rest false.
Basically I need it to
Loop until Column A is empty starting at row 4 carrying out the main body of the macro only IF column I = True.
I have tried to space the code to show 'key' areas.
I appreciate any help!!!
I am strugling (rookie) with a loop. I think I have the ending of the loop wrong some how?
Currently the code selects the folder location then says 'CC Reports completed'.
As I am trying to test it, column A has data 4-100 rows long. Column I has data 4-19 with 4 showing true the rest false.
Basically I need it to
Loop until Column A is empty starting at row 4 carrying out the main body of the macro only IF column I = True.
I have tried to space the code to show 'key' areas.
I appreciate any help!!!
Code:
Sub CCReports()
Dim T As Integer
Dim fldr As FileDialog
Dim sItem As String
Application.ScreenUpdating = False
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
T = 4
Do Until IsEmpty(Cells(T, 1))
Sheets("CC's Included").Select
CLP = Range("C" & T)
CLG = Range("J" & T) & ".xlsx"
If Range("I" & T) = True Then
Sheets("CC's Included").Range("A" & T).Copy
Sheets("Report").Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Sheets("CC's Included").Range("B" & T).Copy
Sheets("Report").Range("A2").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Sheets("Report").Select
ActiveSheet.Range("$AR$4:$AR$220").AutoFilter Field:=1, Criteria1:="Show"
Sheets("Report").Range("$A$1:$AP$250").Copy
Dim SPath As String, SFile As String
Dim Wb As Workbook
SPath = "O:\_DRXSites\UK_TAM\FP\_FP8\Controlling\Controlling\Management Accounts 2019\01 - Cost Centre Reports\Master Files"
SFile = SPath & "Report Temp Dump - DO NOT DELETE.xlsx"
Set Wb = Workbooks.Open(SFile)
Sheets("Sheet1").Range("A1").PasteSpecial xlPasteValues
Sheets("Sheet1").Range("A1").PasteSpecial xlPasteFormats
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:= _
sItem & "" & CLP & "" & CLG _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Windows("Monster File.xlsb").Activate
End If
T = T + 1
Loop
Application.ScreenUpdating = True
MsgBox ("CC Reports completed.")
End Sub
Last edited by a moderator: