Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default AND if syntax

THanks very much, this macro creates all the right page breaks except the
first one.
The first row dept doesn't need a pagebreak above it. So I tried to add an
ANd if to the conditional. And if it is the first row then don't do the
page break.
I don't know how to add a second condition to the first condition. Row 1 is
the header line, row 2 is the first department header. i don't want a page
break there.

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 AND if rng < .Range(r2) Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default AND if syntax

If you want to exclude row 1, why not start in row 2

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A2"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

or to go with your current approach:

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 AND if rng.row 1 Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

--
Regards,
Tom Ogilvy




"Janis" wrote:

THanks very much, this macro creates all the right page breaks except the
first one.
The first row dept doesn't need a pagebreak above it. So I tried to add an
ANd if to the conditional. And if it is the first row then don't do the
page break.
I don't know how to add a second condition to the first condition. Row 1 is
the header line, row 2 is the first department header. i don't want a page
break there.

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 AND if rng < .Range(r2) Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default AND if syntax

Thanks I'll try it your way, to answer your question becuase I thought going
from the bottom was easiest.

"Tom Ogilvy" wrote:

If you want to exclude row 1, why not start in row 2

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A2"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

or to go with your current approach:

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 AND if rng.row 1 Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

--
Regards,
Tom Ogilvy




"Janis" wrote:

THanks very much, this macro creates all the right page breaks except the
first one.
The first row dept doesn't need a pagebreak above it. So I tried to add an
ANd if to the conditional. And if it is the first row then don't do the
page break.
I don't know how to add a second condition to the first condition. Row 1 is
the header line, row 2 is the first department header. i don't want a page
break there.

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 AND if rng < .Range(r2) Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default AND if syntax

Starting in row 2 and using xlup are not inconsistent as you should see from
the code I altered. (unless the whole column is empty)

--
Regards,
Tom Ogilvy


"Janis" wrote:

Thanks I'll try it your way, to answer your question becuase I thought going
from the bottom was easiest.

"Tom Ogilvy" wrote:

If you want to exclude row 1, why not start in row 2

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A2"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

or to go with your current approach:

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 AND if rng.row 1 Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

--
Regards,
Tom Ogilvy




"Janis" wrote:

THanks very much, this macro creates all the right page breaks except the
first one.
The first row dept doesn't need a pagebreak above it. So I tried to add an
ANd if to the conditional. And if it is the first row then don't do the
page break.
I don't know how to add a second condition to the first condition. Row 1 is
the header line, row 2 is the first department header. i don't want a page
break there.

Sub SSPPageBreak2()
Dim Rng As Range
Dim rngToSearch As Range
With ActiveSheet
Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))

For Each Rng In rngToSearch
If Rng.Interior.ColorIndex = 15 AND if rng < .Range(r2) Then

ActiveSheet.HPageBreaks.Add befo=Rng
End If
Next Rng
End With
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA syntax dhstein Excel Discussion (Misc queries) 3 March 13th 09 12:53 PM
The NOW() syntax Tom Excel Discussion (Misc queries) 3 January 4th 08 04:10 PM
Need syntax help! FCC[_6_] Excel Programming 6 June 30th 06 10:30 AM
SQL syntax Jeffiec Excel Programming 1 June 14th 05 05:47 PM
Help with VBA syntax jacqui[_2_] Excel Programming 3 January 13th 04 02:29 PM


All times are GMT +1. The time now is 08:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"