VBA Error 424 - Inserting Rows at Page Breaks and then copying offset string to cell A in active row

MikeL

Active Member
Joined
Mar 17, 2002
Messages
492
Office Version
  1. 365
Platform
  1. Windows
Hi,
Any thoughts as to why a '424' error and how to make this work?
It does insert 2 rows at each page break. But then I need to copy the nearest value in column A to the active row.

Sub PageBreaks2()
Dim sh As Worksheet
Set sh = ActiveSheet
Dim hPage As HPageBreak

For Each hPage In sh.HPageBreaks
hPage.Location.EntireRow.Resize(2).Insert Shift:=xlDown

Cells(ActiveCell.Row, "A").Activate

If cell.Offset(-1, 0).Value <> "" Then
cell.Value = cell.Offset(-1, 0).Value
Else
cell.Value = cell.End(xlUp).Value
End If

Next hPage

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
VBA Code:
Sub PageBreaks2()
Dim sh As Worksheet
Set sh = ActiveSheet
Dim hPage As HPageBreak
Dim cell As Range
For Each hPage In sh.HPageBreaks

hPage.Location.EntireRow.Resize(2).Insert Shift:=xlDown
Set cell = Cells(ActiveCell.Row, "A")
'cell.Activate
If cell.Offset(-1, 0).Value <> "" Then
cell.Value = cell.Offset(-1, 0).Value
Else
cell.Value = cell.End(xlUp).Value
End If

Next hPage

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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