Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 14th, 2004, 10:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default Print selected rows

Hi.
I need to select the rows in my sheet without background color and I do that, with this code snippet, but I can't figure out how to apply my new Range to a Select. Anyone?
Code:
  Dim strRange As String
  Range("A1").CurrentRegion.Select
  With Selection
    For Each r In .Rows
      If r.Interior.ColorIndex = xlColorIndexNone Then
        strRange = strRange & returnRangeForRow(r.Address) & ", "
      End If
    Next r
  End With
  strRange = Right(strRange, (Len(strRange) - 1))

Public Function returnRangeForRow(ByVal strRange As String)
  strRange = Right(strRange, (Len(strRange) - InStrRev(strRange, "$"))) '"$A$38"
  strRange = strRange & ":" & strRange  '"38"
  returnRangeForRow = strRange  '"38:38"
End Function
I tried a million things that I won't list here but I can say it's not as easy as typing: Range("1" & strRange).Select
Selection.Offset(0, 1).Select
Selection.PrintOut Copies:=1, Preview:=True, Collate:=True

- mega
Moving to C# .NET
__________________
 - mega
Aspiring JavaScript Ninja
Reply With Quote
  #2 (permalink)  
Old December 15th, 2004, 11:26 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is a method. However, if you want to print the rows Excel will put each one on a separate page. Better to hide the unwanted ones.
Code:
Sub test()
    Dim PrintRange As Range
    '-----------------------
    If Selection.Cells.Count = 1 Then Exit Sub
    With Selection
        For Each r In .Rows
            If r.Interior.ColorIndex = _
                    xlColorIndexNone Then
                If PrintRange Is Nothing Then
                    Set PrintRange = r
                Else
                    Set PrintRange = _
                        Union(PrintRange, r)
                End If
            End If
        Next r
    End With
    PrintRange.Select
    PrintRange.PrintPreview
End Sub
-----------------------
Regards BrianB
Most problems occur from starting at the wrong place.
Use a cup of coffee to make Windows run faster.
It is easy until you know how.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I hide Excel rows with zero values-no print LMG VB How-To 0 April 24th, 2007 04:37 PM
print the hidden page without the print dialog box kayzem Classic ASP Basics 0 April 21st, 2005 11:31 PM
Print and print preview file on the website withou appleLover General .NET 0 February 19th, 2005 02:24 AM
print multiple times..multiple rows... abhit_kumar JSP Basics 3 January 18th, 2005 07:11 PM
syntax error on <option selected="selected"> hamid HTML Code Clinic 1 October 13th, 2004 09:20 AM



All times are GMT -4. The time now is 05:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.