Run-time error '9' Help

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Code:
Private Sub cmdbtnSearch_click()            
    
    Dim totRows As Long, i As Long
    
    totRows = Worksheets("Sheet5(Slat)").Range("C3").CurrentRegion.Rows.Count
    
    For i = 3 To totRows
        If Trim(Sheet5.Cells(i, 3)) = Trim(TextBox1.Text) Then
            TextBox1.Text = Sheet5.Cells(i, 3)
            TextBox2.Text = Sheet5.Cells(i, 4)
            TextBox3.Text = Sheet5.Cells(i, 5)
            TextBox4.Text = Sheet5.Cells(i, 6)
            Exit For
        End If
    Next i
    
End Sub

I not exactly sure what is wrong with this code. I found this code from a youtube video
http://www.youtube.com/channel/UC-vzNYU9x8IYPk_r89mGvXA
This video is 11 minutes and 24 seconds long. However, the above code ends at 5 minutes and 53 seconds. I had to change some things to fit my project. I typed everything he did. So I'm not certain what I did wrong. When I click on Debug the following line of code is highlighted:
Code:
totRows = Worksheets("Sheet5(Slat)").Range("C3").CurrentRegion.Rows.Count
This is a test for another project. If I am able to fix this error then all I would have to do, I think, is substitute the names of the textboxes with my formula variables. Thank you.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do you have a worksheet called Sheet5(Slat)? Is there a Sheet5 and do you have text boxes called TextBox1/2/3/4?
 
Upvote 0
As you have given us no information at all, this is a pure guess.
Code:
totRows = Sheet5.Range("C3").CurrentRegion.Rows.Count
 
Upvote 0
This is a test for another project.
Why am I getting this error for this line of code. Yes, sheet 5 is named slat. The code below is where Debug states the error is located.
Code:
totRows = Worksheets("Sheet5(Slat)").Range("C3").CurrentRegion.Rows.Count
thank You
 
Upvote 0
If what Fluff posted doesn't work (you haven't responded to that post and I am not 100% sure if Sheet5 is the codename or the Index) try...

Code:
totRows = Worksheets("Slat").Range("C3").CurrentRegion.Rows.Count
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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