Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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

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?
  Dim strRange As String
  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
  #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

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.
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
                    Set PrintRange = _
                        Union(PrintRange, r)
                End If
            End If
        Next r
    End With
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.

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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.