Reputation: 129
My data set is all in column A and i am trying to read between rows 2 and 300. I need to read each cell to see if it has information in it. If it does not have any information then it will go to the next cell below. When it does find information in a cell it needs to create a new work book and use that cell value as the title as the workbook name and loop till row 300. The work book needs to be saved on my dekstop in folder called test. I keep getting "end if without block if" error
Sub blair()
Dim strName As String
strName = ActiveCell.Value
For ptr = 2 To 300
If Cells(ptr, "a") = vbNullString Then
Cells(ptr, "a") = Cells(ptr, "a").Offset(-1, 0)
Else
Set NewBook = Workbooks.Add
With NewBook
.SaveAs Filename:="C:\Users\Marco\Desktop\test\" & strName & ".xls"
.Close
End If
Next
End Sub
Upvotes: 0
Views: 205
Reputation: 8942
The error happens because you have not ended the With
segment with the proper End With
statement. VBA interprets the End
as ending the With
segment and then proceeds to have 2 Ifs
open with none closed.
Upvotes: 5