I have some code
Sub Test2()
Dim ws As Worksheet
Dim rCell As Range
Dim i As Long
Dim resultArray() As String
Dim resultIndex As Long
'ClearImmediateWindow
'Application.VBE.Windows("Immediate").Visible = True
'Debug.Print vbLf & Format(Now(), "dd-mmm-yyyy HH:mm:ss")
Application.VBE.Windows("Immediate").Close
Application.VBE.Windows("Immediate").Visible = True
Set ws = ThisWorkbook.ActiveSheet ' Adjust this to get the sheet you need
resultIndex = 0 ' Initialize the result index
For i = 1 To 12
Set rCell = Cells(i, "C")
If HasAnyBorder(rCell) Then
' Store the result in the array
ReDim Preserve resultArray(resultIndex)
resultArray(resultIndex) = "Cell C" & i & " True"
Else
ReDim Preserve resultArray(resultIndex)
resultArray(resultIndex) = "Cell C" & i & " False"
End If
resultIndex = resultIndex + 1
Next i
' Print the accumulated results to the Immediate Window
For i = LBound(resultArray) To UBound(resultArray)
Debug.Print resultArray(i)
Next i
End Sub
Sub ClearImmediateWindow()
' Simulate pressing Ctrl+G (to activate the Immediate Window)
Application.SendKeys "^g"
' Simulate pressing Ctrl+A (to select all content)
Application.SendKeys "^a"
' Simulate pressing the Delete key (to clear the selected content)
Application.SendKeys "{DEL}"
Application.SendKeys "{f7}" ' Go back to VBE Project Window
End Sub
Function HasAnyBorder(rngCell As Range) As Boolean
HasAnyBorder = rngCell.Value <> "" Or _
rngCell.Borders(xlEdgeTop).LineStyle <> xlNone Or _
rngCell.Borders(xlEdgeBottom).LineStyle <> xlNone Or _
rngCell.Borders(xlEdgeLeft).LineStyle <> xlNone Or _
rngCell.Borders(xlEdgeRight).LineStyle <> xlNone
End Function
The problem is that each time I run this the Immediate Window clears then fills with the other debug.print items so fast it is impossible to read. And a timed approach to each message works to slow it down but after the final it still clears the window.
I’m hoping to a) run the code so that it refreshes the Immediate Window.
b) run the code
c) outputs relevant debug messages
d) stop processing but leave the Immediate Window Debug messages intact until the code is re-run.
Debug.Print ""
as first line of code as suggested by somebody else
Application.VBE.Windows("Immediate").Close
Application.VBE.Windows("Immediate").Visible = True
To test the code put some borders Left, right, top bottom of various cells in Col “C” results should be something like:
Cell C1 True
Cell C2 True
Cell C3 True
Cell C4 False
Cell C5 False
Cell C6 False
Cell C7 False
Cell C8 False
Cell C9 False
Cell C10 False
Cell C11 False
Cell C12 False
cheers for your considerations: Stephen G6SGA