+ Reply to Thread
Results 1 to 5 of 5

vba range define

Hybrid View

  1. #1
    Registered User
    Join Date
    04-30-2009
    Location
    tokyo
    MS-Off Ver
    Excel 2016
    Posts
    43

    vba range define

    Hello

    I am trying to define a range using the sheets assignment like below

    Public Sub TEST()
    sh = Sheet1.Cells(4, 3).Value
    Set rngChart = Sheets(sh).Range(Cells(8, 1), Cells(209, 44))
    End Sub
    I get an error. what am I missing?

    Thanks

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: vba range define

    Option Explicit
    
    Public Sub TEST()
    Dim sh, rngChart As Range
    sh = Sheet1.Cells(4, 3).Value
    Set rngChart = Sheets(sh).Range(Cells(8, 1), Cells(209, 44))
    End Sub

  3. #3
    Registered User
    Join Date
    04-30-2009
    Location
    tokyo
    MS-Off Ver
    Excel 2016
    Posts
    43

    Re: vba range define

    thank you, I guess I messed that

  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: vba range define

    Should not the "Cells" have the sheet defined?
    Public Sub TEST()
    Dim sh, rngChart As Range
    sh = Sheet1.Cells(4, 3).Value
    Set rngChart = Sheets(sh).Range(Sheets(sh).Cells(8, 1), Sheets(sh).Cells(209, 44))
    End Sub
    or
    Public Sub TEST()
        Dim sh, rngChart As Range
        sh = Sheet1.Cells(4, 3).Value
        With Sheets(sh)
            Set rngChart = .Range(.Cells(8, 1), .Cells(209, 44))
        End With
    End Sub
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  5. #5
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: vba range define

    Btw, this appears to have been cross-posted here

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How can i define below start range as range given in a cell to do a Loop ?? Please help
    By akash kothari in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-25-2015, 12:25 PM
  2. [SOLVED] Define new range names based on existing range name offset 1 column to right
    By jprlimey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2014, 07:53 PM
  3. excel macro range define to another sheet / named range
    By koi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2013, 10:25 AM
  4. Define range to select from current cell in a full range (using worksheet_change)
    By draddy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2013, 11:48 AM
  5. [SOLVED] Using cell value to define a range (for a variable defined as a range)
    By Sccye in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-02-2012, 10:25 AM
  6. Define named range where user can define size
    By nahousto in forum Excel General
    Replies: 4
    Last Post: 07-06-2009, 05:09 PM
  7. Define variable range as named range
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2008, 09:28 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1