+ Reply to Thread
Results 1 to 3 of 3

VBA defining range only works on selected sheets

  1. #1
    Registered User
    Join Date
    08-28-2018
    Location
    London
    MS-Off Ver
    2017
    Posts
    1

    VBA defining range only works on selected sheets

    I am trying to get the following code to work:

    Sub testingthecell()

    Dim cell As Range, cell2 As Range

    Set cell = Worksheets("Sheet2").Range(Range("B8"), Range("B8").End(xlDown))
    Set cell2 = Worksheets("BACKUP").Range(Range("L19"), Range("L19").End(xlDown))
    ReDim EUrownum(cell.count)
    ReDim ukrownum(cell2.count)

    End Sub

    I have also tried to refer to the Workbooks("name"). before the rest of this but for some reason to run it I first have to be on sheet 2 and then it will highlight cell2 with an error and then I have to move onto the BACKUP sheet and run to get cell2 to obtain a value. Does anyone know what is wrong here?

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,902

    Re: VBA defining range only works on selected sheets

    You need to qualify all the ranges. try
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA defining range only works on selected sheets


    Hi !

    Set cell = .Range("B8", .[B8].End(xlDown))

+ 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] DoubleClick Event works only in selected range
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-11-2014, 02:09 AM
  2. AVERAGEIF, defining range across multiple sheets
    By waringb in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-02-2013, 02:42 PM
  3. Defining a range to highlight column and row in line with selected cell
    By ACM2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-19-2012, 11:13 PM
  4. Replies: 6
    Last Post: 03-29-2006, 07:50 AM
  5. Replies: 6
    Last Post: 03-29-2006, 07:50 AM
  6. Replies: 6
    Last Post: 03-29-2006, 07:50 AM
  7. Replies: 2
    Last Post: 03-30-2005, 03:06 PM

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