Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All,
I'm using the following code to insert a hpagebreak everytime a specific value ("Cuenta") is found. The problem is that although it works perfectly in a simple test workbook, it returns the '1004' Runtime error (Application or Objet defined error) when I try to use it in a more complex workbook. Sub addhpb() Dim rng As Range Worksheets(1).ResetAllPageBreaks For Each rng In ActiveSheet.Range("b1:b82") If Not rng.Row = 1 Then If rng.Value = "Cuenta" Then ActiveSheet.HPageBreaks.Add Befo=Range("b" & rng.Row).EntireRow.Offset(-2) End If End If Next rng End Sub Thanks in Advance! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You will get that error if it encounters Cuenta in row 2, try this
If Not rng.Row <= 2 Then You could do away with the entire if/end if loop by changing you range to start in B3 in the other nested loop Mike "AshMorK" wrote: Hi All, I'm using the following code to insert a hpagebreak everytime a specific value ("Cuenta") is found. The problem is that although it works perfectly in a simple test workbook, it returns the '1004' Runtime error (Application or Objet defined error) when I try to use it in a more complex workbook. Sub addhpb() Dim rng As Range Worksheets(1).ResetAllPageBreaks For Each rng In ActiveSheet.Range("b1:b82") If Not rng.Row = 1 Then If rng.Value = "Cuenta" Then ActiveSheet.HPageBreaks.Add Befo=Range("b" & rng.Row).EntireRow.Offset(-2) End If End If Next rng End Sub Thanks in Advance! |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You are starting at the first row with code to go back 2, you need to handle
what to do if it is encountered in the first two rows. -- -John Please rate when your question is answered to help us and others know what is helpful. "AshMorK" wrote: Hi All, I'm using the following code to insert a hpagebreak everytime a specific value ("Cuenta") is found. The problem is that although it works perfectly in a simple test workbook, it returns the '1004' Runtime error (Application or Objet defined error) when I try to use it in a more complex workbook. Sub addhpb() Dim rng As Range Worksheets(1).ResetAllPageBreaks For Each rng In ActiveSheet.Range("b1:b82") If Not rng.Row = 1 Then If rng.Value = "Cuenta" Then ActiveSheet.HPageBreaks.Add Befo=Range("b" & rng.Row).EntireRow.Offset(-2) End If End If Next rng End Sub Thanks in Advance! |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Perhaps you have "Cuenta" in row 2 or 3
-- Don Guillett Microsoft MVP Excel SalesAid Software "AshMorK" wrote in message ... Hi All, I'm using the following code to insert a hpagebreak everytime a specific value ("Cuenta") is found. The problem is that although it works perfectly in a simple test workbook, it returns the '1004' Runtime error (Application or Objet defined error) when I try to use it in a more complex workbook. Sub addhpb() Dim rng As Range Worksheets(1).ResetAllPageBreaks For Each rng In ActiveSheet.Range("b1:b82") If Not rng.Row = 1 Then If rng.Value = "Cuenta" Then ActiveSheet.HPageBreaks.Add Befo=Range("b" & rng.Row).EntireRow.Offset(-2) End If End If Next rng End Sub Thanks in Advance! |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Mike!!
Now it runs OK. "Mike H" wrote: You will get that error if it encounters Cuenta in row 2, try this If Not rng.Row <= 2 Then You could do away with the entire if/end if loop by changing you range to start in B3 in the other nested loop Mike "AshMorK" wrote: Hi All, I'm using the following code to insert a hpagebreak everytime a specific value ("Cuenta") is found. The problem is that although it works perfectly in a simple test workbook, it returns the '1004' Runtime error (Application or Objet defined error) when I try to use it in a more complex workbook. Sub addhpb() Dim rng As Range Worksheets(1).ResetAllPageBreaks For Each rng In ActiveSheet.Range("b1:b82") If Not rng.Row = 1 Then If rng.Value = "Cuenta" Then ActiveSheet.HPageBreaks.Add Befo=Range("b" & rng.Row).EntireRow.Offset(-2) End If End If Next rng End Sub Thanks in Advance! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
AutoRun Macro with a delay to give user the choice to cancel the macro | Excel Programming | |||
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort | Excel Worksheet Functions | |||
Need syntax for RUNning a Word macro with an argument, called from an Excel macro | Excel Programming | |||
how to count/sum by function/macro to get the number of record to do copy/paste in macro | Excel Programming | |||
Start Macro / Stop Macro / Restart Macro | Excel Programming |