Hmm, I keep finding new ways to break the script... This might be easier... This is how it was originally. This just copies the entire column instead of cell by cell. The Issue I have with this is that it copies blank cells and cells with "?"'s in them. My goal is to have it copy the invoice number from the cell in column C and past it into a new sheet to be saved as a new workbook, and where that invoice number exists I want it to copy the cell with the total hours in column G of the same row... I know a lot about this code is unnecessary, I am VERY new to VBA and trying to frankenstien this code together from existing scripts and my basic knowledge....
Function SheetExists(sheetName As String)
Dim sheet As Worksheet
For Each sheet In Sheets
If sheet.Name = sheetName Then
SheetExists = True
Exit Function
Else
SheetExists = False
End If
Next
End Function
Function SaveWorkbook(workbookName As String)
Dim filePath As String
Application.DisplayAlerts = False
filePath = "C:\Users\chrish\Desktop\Job Costing\dump\output.xlsx"
Sheets(workbookName).Copy
ActiveWorkbook.SaveAs Filename:=filePath
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Function
Sub CreateWorkbooks()
Dim newSheet As Worksheet, timecodeSheet As Worksheet
Dim cell As Object
Dim regionRange As String
Set timecodeSheet = Sheets("Sheet1")
Application.ScreenUpdating = False
regionRange = "C4:" & timecodeSheet.Range("C4").End(xlDown).Address
For Each cell In timecodeSheet.Range(regionRange)
If SheetExists(cell.Value) = False Then
Sheets.Add After:=Sheets(Sheets.Count)
Set newSheet = ActiveSheet
timecodeSheet.Range("C4").EntireColumn.Copy newSheet.Range("A1")
timecodeSheet.Range("G4").EntireColumn.Copy newSheet.Range("B1")
newSheet.Name = cell.Value
SaveWorkbook (cell.Value)
Application.DisplayAlerts = False
newSheet.Delete
Application.DisplayAlerts = True
End If
Next cell
MsgBox "All workbooks have been created successfully"
Application.ScreenUpdating = True
End Sub
I attached the file as well.
Bookmarks