Hi all
I have a macro which imports text files to new sheets, but to stop the file from becoming too large, I want it to stop the import macro when the sheet count reaches 8, then open a new file and restart it.
Heres my current code
It functions correctly, but won't stop at 8, nor will it save or close the file afterwards. How can i change this to stop at sheet 8, save it, open a new sheet and continue from where it left off?
Thanks
I have a macro which imports text files to new sheets, but to stop the file from becoming too large, I want it to stop the import macro when the sheet count reaches 8, then open a new file and restart it.
Heres my current code
Code:
Sub Selection()
Set Rng = Tabelle2.Range("A3:A65536")
Dim b As Object
Dim SaveFile As String
SaveFile = "\Comparisons" & ".xls"
Application.SheetsInNewWorkbook = 1
Set NewBook = Workbooks.Add
For Module1.i = 3 To 15000
ThisFile = Tabelle2.Cells(i, 1).Value
If Tabelle2.Cells(Module1.i, 1).Font.Bold = True Then
Set NewSheet = Worksheets.Add
With NewSheet
ActiveSheet.name = ThisFile
End With
If Tabelle2.Cells(Module1.i, 1).Font.Bold = True Then Call Importselect
End If
If ThisWorkbook.Sheets.Count = 8 Then
With NewBook
.SaveAs Filename:=ThisWorkbook.Path & SaveFile
End With
ActiveWorkbook.Close False
End If
Next i
End Sub
Thanks