Consulting

Results 1 to 3 of 3

Thread: Select range till last empty row

  1. #1

    Select range till last empty row

    For the excel sheet, I'd like to print multiple sheets automatically. The printing VBA code I can mangage, but selecting the range is too hard. I need to select in the tab "RD" from A1 till the first empty row, and for the tab "IB" from the cell C1 till the same row as before, but -4 (due to lay-out). I can't let it select till the last empty row on that tab, because due to other formula's there are automatically values in there.

    Anyone who can help me? In the attachment you can also see the range it should select after the macro has run.


    DSVS-17-KW01.xlsm

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    I didn't see any ranges in the attachment that were selected

    Did you really want all those blank pages printed?

    This macro will find the useful data on the two sheets using what I understood to be the rules

    If you want something else, give the specific addresses of the ranges you want



    Option Explicit
    Sub FindRows()
        Dim rUsed As Range, rWanted As Range
        Dim r As Long, c As Long
        
        With Worksheets("RD")
            Set rUsed = .UsedRange
            
            r = rUsed.Rows.Count
            Do While Application.WorksheetFunction.Count(rUsed.Rows(r)) = 0
                r = r - 1
            Loop
        
            c = rUsed.Columns.Count
            Do While Application.WorksheetFunction.Count(rUsed.Columns(c)) = 0
                c = c - 1
            Loop
        
            Set rWanted = Range(.Cells(1, 1), .Cells(r, c))
        
            MsgBox "RD range = " & rWanted.Address
        End With
        
        
        With Worksheets("IB")
        
            Set rUsed = .UsedRange
        
            c = rUsed.Columns.Count
            Do While Application.WorksheetFunction.Count(rUsed.Columns(c)) = 0
                c = c - 1
            Loop
            Set rWanted = Range(.Cells(1, 3), .Cells(r - 4, c))
            MsgBox "IB range = " & rWanted.Address
        End With
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Thanks Paul,

    I needed the useful range to be selected, but that is easy to extract from what you wrote. This way I can let it print out the selected range.

    Thanks for your help
    Flemming

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •