+ Reply to Thread
Results 1 to 2 of 2

Problem with finding a MATCH in a Range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Problem with finding a MATCH in a Range

    The following code takes values from a userform and puts them in the required place of the required worksheet.
    Sub EnterIn(Name, w_C, Mac, Meters, hours, jobs, cols, washes)
     
        Dim ws As Worksheet
    Select Case Mac
            Case "MA1"
                Set ws = Sheets("MARKANDYS1")
                 McRow = 0
                 Manrow = 9
            Case "MA2"
               Set ws = Sheets("Markandys2")
                   McRow = 0
                   Manrow = 9
            Case "SR1"
              Set ws = Sheets("SLITTERS1")
                   McRow = 0
                   Manrow = 9
            Case "OMEGA"
              Set ws = Sheets("SLITTERS1")
                   McRow = 26
                   Manrow = 25
            Case "410"
              Set ws = Sheets("SLITTERS2")
                   McRow = 0
                   Manrow = 9
            Case "OPAL 2"
              Set ws = Sheets("SLITTERS2")
                   McRow = 26
                   Manrow = 25
                   
            Case "ROTOFLEX"
              Set ws = Sheets("SLITTERS2")
                  McRow = 52
                  Manrow = 61
            Case Else
            MsgBox ("You must Enter a Machine")
        Exit Sub
        
        End Select
        If ws.Name = "MARKANDYS1" Or ws.Name = "MARKANDYS2" Then
        ReDim enterAr(4) As Variant
            enterAr(0) = Meters
            enterAr(1) = hours
            enterAr(2) = jobs
            enterAr(3) = cols
            enterAr(4) = washes
                
            
        End If
        If ws.Name = "SLITTERS1" Or ws.Name = "SLITTERS2" Then
        ReDim enterAr(2) As Variant
           enterAr(0) = Meters
           enterAr(1) = hours
            enterAr(2) = jobs
         End If
         With ws
    
          
            r = Application.WorksheetFunction.Match(Name, .Range(Cells(10 + McRow, 4), Cells(30 + McRow, 4)), 0)
    
           c = Application.WorksheetFunction.Match(w_C, .Range("G9:BF9"), 0)
           
              Dim Destination As Range
              Set Destination = ws.Cells(r + Manrow, c + 6)
                    Set Destination = Destination.Resize(UBound(enterAr) + 1, 1)
               Destination.Value = Application.Transpose(enterAr)
        .Range(.Cells(r + ManRow, c + 6), .Cells(r + 5 + ManRow, c + 6)).Value = enterAr
    End With
    End Sub
    When this is triggered (by a button on the user form ), if it is directly after opening the application this fails with a error message "Method Range of object __Worksheet failed"

    If I then restart the application by clicking Run when the userform code is showing it runs as required with the data put in the correct place.
    I need some help to understand what is going wrong.
    John

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

    Re: Problem with finding a MATCH in a Range

    Without knowing where it fails, or having a workbook to test on, this is a guess.
    Try adding a . before cells on this line
    r = Application.WorksheetFunction.Match(Name, .Range(.Cells(10 + McRow, 4), .Cells(30 + McRow, 4)), 0)

+ 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. Finding partial match in a range
    By miucus in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-24-2019, 10:14 PM
  2. Match or Vlookup: Finding the name value within a range of dates?
    By Tia_ in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-01-2016, 03:13 PM
  3. Finding the first cell in a range that does not match a value
    By leepox in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-05-2016, 05:28 PM
  4. Finding value from a range and if not match then find next
    By annux3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2015, 08:44 AM
  5. [SOLVED] Finding MIN value within range and returning MATCH
    By MaddyG in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-16-2012, 03:50 PM
  6. Problem Finding Data in Multiple Columns Using Match Function
    By joshc22 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-12-2012, 04:26 PM
  7. Range match finding
    By calsexceladel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2008, 08:42 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