Run Error 13

HYKE

Active Member
Joined
Jan 31, 2010
Messages
373
Dear All,

What seems to be wrong with this code? It is giving me a runtime error 13????
Code:
Private Sub CommandButton3_Click()
 Dim r As Long
    With Sheet1
         r = Application.Match(MRITRBox.Value, .Range("G:G"), False)
        .Cells(r, 20).Value = MRITRUpd.Value
        
        Range("a1").Select
       
    End With
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
r = Application.Match(MRITRBox.Value, .Range("G:G"), [COLOR=red]0[/COLOR])
 
Last edited:
Upvote 0
The Match function might not be finding a match and returning an error.

Why not try VBA Find?
 
Upvote 0
This particular line
Code:
r = Application.Match(MRITRBox.Value, .Range("G:G"), False)
:(
:(
 
Upvote 0
This is untested but perhaps you could use it or something similar instead of Application.Match
Code:
Private Sub CommandButton3_Click()
Dim rngFnd As Range
 
    With Sheet1
    
        Set rngFnd = .Range("G:G").Find(MRITRBox.Value)
        If Not rngFnd Is Nothing Then
            ' if found
            .Cells(rngFnd.Row, 20).Value = MRITRUpd.Value
        End If
    End With
 
End Sub
Note if nothing is found nothing will happen, but you won't get an error.
 
Upvote 0
What is MRITRBox ? Is it a Text Box?
Text boxes contain.....well....Text..
You won't find a match to a text value in a column of numbers (G).

Perhaps

r = Application.Match(Val(MRITRBox.Value), .Range("G:G"), 0)


Hope that helps.


Note, the reason for 0 instead of FALSE is a little nitpicky..but using FALSE is technically incorrect (even though it works).
The Match function is looking for an argument of either -1, 0, or 1 (it is NOT a True or False argument)

Using TRUE = 1, FALSE = 0. But there is no equivelant for -1.
 
Last edited:
Upvote 0
Hi norie,

Your code worked! Thanks a lot. Now I can rest for a while..been breaking my head for hours. I am just wondering why the previous code didn't work?
 
Upvote 0

Forum statistics

Threads
1,217,481
Messages
6,136,903
Members
450,029
Latest member
MissQuotation

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top