I worked on the top portion of this last week and that doesn't need anything aside from some formatting on my end. The bottom portion with the block style comments are where I am stuck. (below wks.Activate is new)
I am trying to set a do while loop that sequentially reads through a given column until no value is present, then copy the row above and paste the formatting into the blank row.
There are a couple other problems, but I'm just concerned with base functionality at the moment.
The code I have put together so far is as follows:
Public Sub AddNewPage()
Sheets(Sheets.Count).Select 'references last sheet in workbook
Dim wks As Worksheet 'establish static variable wks to reference worksheets
Dim nullVal As Boolean 'set a boolean variable for value check
Dim i As Integer 'set variable as integer for coming loop
Set wks = ActiveSheet 'set wks to be the given, activated sheet (dynamic variable)
ActiveSheet.Copy After:=Worksheets(Sheets.Count) 'sets the last sheet in the workbook as the active sheet and copies it
Range("H9").Value = Range("H9").Value + 1 'sets value of cell H9 in new worksheets to sequentially increase by 1
If wks.Range("H9").Value <> "" Then 'If cell "H9" in activated worksheet has a value then...
On Error Resume Next 'Proceed even if I beak stuff
wks = Sheets(Sheets.Count).Select 'sets wks to reference last sheet in given workbook
ActiveSheet.Name = wks.Range("H9").Value + 1 'sets page title to sequentially increase by 1 with each iteration
End If
wks.Activate
Application.Worksheets("Log").Activate 'redirect to primary sheet used for tracking workbook data
Do While nullVal = False 'establishing a do while loop to scan cells until no value is found
For i = 1 To 1000 '*************************
If Cells(i, 1).Value <> "" Then '*This is my problem
nullVal = False '*area, I think.
i = i + 1 '*
Else: nullVal = True '*The goal is to create
End If '*a do while loop that
Next i '*scans cells in the given
'*column until no value
If nullVal = True Then Exit Do '*is found and copy the
If nullVal = True Then Exit Sub '*above row's formatting
'*into the blank row.
Loop '*(see below)
'*************************
If nullVal = True Then
wks.Cells(i, 1).End(xlUp).Offset(1, 0).Select '**********************************
Rows(Selection.Row - 1).Copy '*Another minor bug in here as it
Rows(Selection.Row).Insert Shift:=xlDown '*won't necessarily select the last
Rows(Selection.Row).ClearContents '*row if the user is in the sheet
Application.CutCopyMode = False
End If
End Sub
It's somewhat functional at this point, with bugs.
Any other sets of eyes and any depth of knowledge would be appreciated as I just started learning this... thing (VBA) and I've been working on and off with this for days now.
I am curious as to whether an array or table might serve me well here.