+ Reply to Thread
Results 1 to 6 of 6

Errors with Ranges

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Errors with Ranges

    Hello,

    I am sorry to always be asking about ranges... I keep getting an error that says "method range of worksheet object failed". It is the line that says Set Vbr... I am so confused because I have never had this problem before when dealing with ranges.

    If anyone can help me out, I'd greatly appreciate that. Thanks!

    Dim k, j, m, n As Integer
        Dim reticle As String
        Dim numberOfRows As Integer
        Dim Wg As Double
        Dim i As Integer
        Dim id As String
        Dim idss As Double
        Dim vbr As Range
       
        
        
        i = 1 'Vbr column
        k = 6 'id(A/um) column
        j = 2 'reticle number
        n = 2 'id column
        
           
      
       Set vbr = Range(i & "123", Range(i & rows.count).End(xlUp))

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Errors with Ranges

    When using Range on it's own you need to use the column letter, not the column number.

    If you want to use the number use Cells with Range.
    Dim k, j, m, n As Integer
        Dim reticle As String
        Dim numberOfRows As Integer
        Dim Wg As Double
        Dim i As Integer
        Dim id As String
        Dim idss As Double
        Dim vbr As Range
       
        
        
        i = 1 'Vbr column
        k = 6 'id(A/um) column
        j = 2 'reticle number
        n = 2 'id column
        
           
      
       Set vbr = Range(Cells(123, i), Cells(Rows.Count, i).End(xlUp))
    If posting code please use code tags, see here.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Errors with Ranges

    Hi, NatalieE,

    Range expects a Column like A and not the number as the first argument, use Cells instead and try
    Dim k, j, m, n As Integer
        Dim reticle As String
        Dim numberOfRows As Integer
        Dim Wg As Double
        Dim i As Integer
        Dim id As String
        Dim idss As Double
        Dim vbr As Range
       
        
        
        i = 1 'Vbr column
        k = 6 'id(A/um) column
        j = 2 'reticle number
        n = 2 'id column
        
           
      
       Set vbr = Range(Cells(123, i), Cells(Rows.Count, i).End(xlUp))
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Errors with Ranges

    Hi, Norie,

    sorry: no preview available at present so I merely posted the same code only hours later.

    Holger

  5. #5
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Re: Errors with Ranges

    Thank you so much everyone!

    I did use a line before where I used the column number, and it worked. I must have set something up differently. I am still learning

  6. #6
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Re: Errors with Ranges

    Now I have a new error! Why can't I set vbr in a while loop?

    
    Dim k, j, m, n As Integer
        Dim reticle As String
        Dim numberOfRows As Integer
        Dim Wg As Double
        Dim i As Integer
        Dim idss As Double
        Dim vbr As Range
       
        Dim label As String
        
        label = "Id (A/um)"
        
        
        i = 1 'Vbr column
        k = 6 'id(A/um) column
        j = 2 'reticle number
        n = 2 'id column
        
           
      
       Set vbr = Range(Cells(123, i), Cells(rows.count, i).End(xlUp))
       numberOfRows = vbr.rows.count + 123
      
       reticle = Cells(1, i).Value
       
       Wg = 1000 * Sheets("Hard Breakdown Summary").Cells(1, 2).Value
       Cells(122, k) = "Id (A/um)"
       
      While reticle <> ""
        
            For m = 123 To numberOfRows
        
                idss = Cells(m, n).Value / Wg
                Cells(m, k) = idss
                
            Next m
        
             i = i + 8
             k = k + 8
             j = j + 8
             n = n + 8
        
            Set vbr = Range(Cells(123, i), Cells(rows.count, i).End(xlUp))
            numberOfRows = vbr.rows.count
            reticle = Cells(1, i).Value
            Cells(122, k) = label
            
        Wend

+ 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. Replies: 1
    Last Post: 03-19-2013, 07:03 PM
  2. Conditional Formatting Using Names Ranges - No Errors?
    By brokenbiscuits in forum Excel General
    Replies: 0
    Last Post: 06-28-2012, 04:37 AM
  3. Errors occuring when creating a set of named ranges
    By Kaigi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2009, 02:57 PM
  4. [SOLVED] "Subscript Out of Range" Errors For Ranges
    By MDW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2006, 06:50 PM
  5. Ignore errors when calculation average of multiple ranges
    By joshkraemer in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-13-2006, 06:30 PM

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