Changing from message box to insertion of text into cells

ardykav

Board Regular
Joined
Oct 18, 2015
Messages
172
Office Version
  1. 365
Platform
  1. Windows
Hi,

Thanks to PGC01 for the below code to show where page breaks are on a sheet. I was just looking to edit the code so that rather than the message box appearing it actually puts the text in the row itself. Something like "There is a page break on this row" in column A would do the trick I think.

Sub pagebreaklook()
Dim hpbs As HPageBreaks
Dim j As Long

Set hpbs = ActiveSheet.HPageBreaks
If hpbs.Count = 0 Then
MsgBox "No horizontal page breaks in active sheet"
Else
For j = 1 To hpbs.Count
MsgBox "Horizontal page break " & j & " at row: " & hpbs(j).Location.Row
Next j
End If
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about

VBA Code:
Sub PageBreakText()
  Dim h As HPageBreak
  For Each h In ActiveSheet.HPageBreaks
    Range("A" & h.Location.Row).Value = "There is a page break on this row"
  Next
End Sub
 
Last edited:
Upvote 0
Absolutely perfect, thanks so much
How about

VBA Code:
Sub pagebreaklook()
  Dim hpbs As HPageBreaks
  Dim j As Long
 
  Set hpbs = ActiveSheet.HPageBreaks
  If hpbs.Count = 0 Then
    MsgBox "No horizontal page breaks in active sheet"
  Else
    For j = 1 To hpbs.Count
      Range("A" & hpbs(j).Location.Row).Value = "There is a page break on this row"
    Next j
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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