Error Checking in Excel
Likes Likes:  0
Results 1 to 4 of 4

Thread: VBA: determination of a range

  1. #1
    Board Regular
    Join Date
    Sep 2017
    Posts
    212
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default VBA: determination of a range

    Hello everybody.

    I have to determine a range in the following situation:

    Code:
    Dim lr As Long, lc As Long
    Dim rng As Range
    
        lr = sheet.Cells(Rows.Count, 1).End(xlUp).Row
        lc = sheet.Cells(i, 1).End(xlToRight).Column
            If lc >= 16 Then lc = 15
       
       
       set rng = ?????
    For example:
    - the beginning cell of the range (top on the left) is D2
    - suppose lr = 10
    - suppose lc = 15
    - rng shoud be ("D2:O10")

    How can I figure it out?

    Thank's.

  2. #2
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    32,144
    Post Thanks / Like
    Mentioned
    24 Post(s)
    Tagged
    3 Thread(s)

    Default Re: VBA: determination of a range

    Code:
    set rng = sheet.range("D2", sheet.cells(lr, lc))
    should do the trick.

  3. #3
    Board Regular
    Join Date
    Sep 2017
    Posts
    212
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA: determination of a range

    Quote Originally Posted by RoryA View Post
    Code:
    set rng = sheet.range("D2", sheet.cells(lr, lc))
    should do the trick.
    Yes, perfect.

    Thank you.

  4. #4
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    32,144
    Post Thanks / Like
    Mentioned
    24 Post(s)
    Tagged
    3 Thread(s)

    Default Re: VBA: determination of a range

    Glad to help.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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