Results 1 to 7 of 7

Thread: [RESOLVED] Selecting ranges

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    28

    Resolved [RESOLVED] Selecting ranges

    I need my Excel spreadsheet to have the ability to select the range from the active cell all the way back to cell A1. I've been writing code for this seemingly simple problem all day and nothing gets past the debugger. For example:

    Range("A1":Range(ActiveCell)).Select

    Can anyone help?

    Danno

  2. #2
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: Selecting ranges

    Close:

    VB Code:
    1. Option Explicit
    2.  
    3. Sub Macro1()
    4. Range("A1", ActiveCell).Select
    5. End Sub




    If you find any of my posts of good help, please rate it

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    28

    Re: Selecting ranges

    Thank you Malik. I could have sworn I tried that line of code, but I guess I didn't because it works perfectly.

    Thanks again,

    Danno

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    28

    Re: [RESOLVED] Selecting ranges

    Malik641 I need you again!

    I'm trying to write a macro that will do the following: The user will click on a cell, that active cell and everything back to cell A1 gets selected and print area set, then print a number of copies. With the help of your line of code I've gotten it to select the desired range, but it prints out the entire worksheet not just the selected range.

    Danno

  5. #5
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: [RESOLVED] Selecting ranges

    Like this?

    VB Code:
    1. Option Explicit
    2.  
    3. Sub Danno()
    4. Dim selectedRng As Range
    5.  
    6. Set selectedRng = Range("A1", ActiveCell)
    7. selectedRng.Select 'This could be left out.
    8.  
    9. ActiveSheet.PageSetup.PrintArea = selectedRng.Address
    10. ActiveWindow.SelectedSheets.PrintOut Copies:=2, Preview:=False, _
    11.         ActivePrinter:="Your printer", Collate:=True
    12. End Sub




    If you find any of my posts of good help, please rate it

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    28

    Re: [RESOLVED] Selecting ranges

    Malik,

    Works perfectly, thank you. I've tried so many iterations that I've forgotten what I wrote. I thought for sure that one of my code attempts had your line: Set selectedRng = Range("A1", ActiveCell) and it did not work. But this line was my missing link and yours works just right.

    Thanks very much,

    Danno

  7. #7
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: [RESOLVED] Selecting ranges

    Hey glad to help Danno




    If you find any of my posts of good help, please rate it

Posting Permissions

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



Click Here to Expand Forum to Full Width