I have a Sub that does some light formatting, and then I need it to evaluate and count whether a column contains a "1" or nothing, and if that column has a header that isNumeric or not.
First iteration of the Do...Until loops functions exactly as it should. However, if I try to run it a second time, it throws the active cell all the way to the rightmost column in the worksheet (XFD). I have a total of about 114,000 rows that I need this to loop through.
Please see code below, with only the first loop; this will need to be nested inside another loop for cycling through all rows:
Sub TotalBookCountsProcess()
Dim ws As Excel.Worksheet
Dim numberedBooks As Integer 'Total Number of physical books
Dim virtualBooks As Integer 'Total Number of virtual books
Dim firstBookCol As Integer 'First Column with a book number
Dim ispeecCol As Integer 'ISPEC Column
Dim lastWorksheetCol As Integer 'Last Column in the worksheet after adding total book count columns
Dim loopColOffset As Integer 'Offset column amounts for new row reset after loop
Dim lastItem As String 'Last item number in last row of the worksheet
ActiveCell.End(xlDown).Select
lastItem = ActiveCell.Value
ActiveCell.End(xlUp).End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Total Numbered Books"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Total CS Books"
lastWorksheetCol = ActiveCell.Column
Columns.AutoFit
numberedBooks = 0
virtualBooks = 0
Cells.Range("1:1").Find("ISPEC").Select
ispecCol = ActiveCell.Column
firstBookCol = ispecCol + 1
ActiveCell.Offset(1, 1).Select
loopColOffset = ((lastWorksheetCol - firstBookCol) * -1)
Do Until ActiveCell.End(xlUp).Value = "Total Numbered Books"
If ActiveCell.Value = 1 And IsNumeric(ActiveCell.End(xlUp).Value) = True Then
numberedBooks = numberedBooks + 1
ActiveCell.Offset(0, 1).Select
ElseIf ActiveCell.Value = 1 And IsNumeric(ActiveCell.End(xlUp).Value) = False Then
virtualBooks = virtualBooks + 1
ActiveCell.Offset(0, 1).Select
Else
ActiveCell.Offset(0, 1).Select
End If
Loop
ActiveCell.Value = numberedBooks
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = virtualBooks
ActiveCell.Offset(1, loopColOffset).Select
End Sub
Any insights very much appreciated.