Printing an Array to Debug.Print command

Prevost

Board Regular
Joined
Jan 23, 2014
Messages
198
Hi There. I am having an issue with printing an Array to the immediate window using Debug.Print. I have a column heading containing HP1 and HP2 and another column heading containing HP3 and HP4. The ideal case is HP1=HP3 and HP2=HP4. I created a new column called HP5 and HP6 which should contain the correct value. This code checks to see if the ideal case is true and if it is, then enters those values in the new columns (and everything is okay). If it is not true, then the row number is added to the Array and at the end the Array should print out all the row values in the immediate window.

My problem is that it does not work as planned. All the cells are changed, but not all the row numbers from the array are printed out. I know that row 4 should be in the array but it does not show in the debug.print.

If I have a message box pop up and show each value in the array, the message box contains row 4 and has all the correct row values so I think I am doing something wrong with the debug.print. Thanks for any help!

Code:
Sub CreateHPColumns()
    
    Dim RowNos()
    Dim i As Long, x As Long
    x = 0
        
        For i = 2 To 28415
            If Cells(i, 10) = Cells(i, 12) And Cells(i, 11) = Cells(i, 13) Then
                Cells(i, 14) = Cells(i, 12)
                Cells(i, 15) = Cells(i, 13)
            Else
                x = x + 1
                ReDim Preserve RowNos(x)
                RowNos(x) = i
            End If
        Next i
        
        For i = 1 To UBound(RowNos)
            Debug.Print (RowNos(i))
        Next i

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Code:
Debug.Print RowNos()

If not the Locals window will show the array being built. step through the code or put a breakpoint in at end sub to be able to veiw array in the Locals window.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top