Consulting

Results 1 to 4 of 4

Thread: Relative selecting to the right (or left)?

  1. #1

    Relative selecting to the right (or left)?

    Hi out there!

    I have a simple problem, that must have a simple solution but i couldnt find one!

    Usually when i want to select a range relatively (with that i mean all the way down, if the cell contains something) i use the following method:


    sht.Range("A1:F" & Range("A1").End(xlDown).Row).ClearContents if i wanted to clear the contents of cells from A1 to F (and then all the way down until there is an empty cell).

    But i would like to replace this "F" now, since i want to be able to expand the width inside the program. How do i do this?
    Put in another way: How do i choose ctrl+shift+down AND THEN ctrl+shift+right and select in vba-language?

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    For specific Ranges
    Range(Range("A1"), Cells(Range("B2").End(xlDown).Row, Range("C3").End(xlRight).Col))
    The Row at the bottom of B and the column at the end of Row 3


    Or
    Range(Range("A1"), Range(Range("A1").End(xlDown).End(xlRight)))
    The end of the Row at the bottom of Column A


    Which is the very similar, but not the same as
    Range("A1").CurrentRegion
    The last continuous row and the last continuous column, starting at A1


    But different than
    Sheets("X").UsedRange
    All used rows and all used columns.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Thank you very much!!! Lots of possibilites now!

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I forgot the most commonly used

    LastCol = Range("A1").End(xlToRight).Column
    LastRow = Range("A1").End(xlDown).Row
    Range(Range("A1"), Cells(LastRow, LastCol))
    LastRow is probably the single most used of all these in VBA for Excel.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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