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!
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