Subscript Out of Range

joshcas

New Member
Joined
Jan 25, 2012
Messages
32
Hi
I’m having a lot of trouble with a sentence of my code because it’s returning a subscript out of range error, what my code is trying to do is filtering the data, base on the user input and if the word exists then show that in the lisbox, if not, show a message to the user, I’m sure there is an easiest way, but I’m good if I can get rid of the error <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>



Code:
Private Sub Image2_Click()
'///////////////////////////////////////////////////////////////////////////////////////////////////////
' Search Button ----------------------------------------------------------------------------------
'///////////////////////////////////////////////////////////////////////////////////////////////////////
 
' Show searching label ...
Image12.Visible = True
 
  With Application
        .ScreenUpdating = False
        .Calculation = xlManual
        .EnableEvents = False
    End With
 
'Application.Calculation = xlCalculationAutomatic
'On Error GoTo ErrorHandler
 
'EnableEvents = False
'Application.ScreenUpdating = False
 
ListBox2.RowSource = ""
ListBox1.RowSource = ""
 
 
Dim T1
Dim T2
Dim T3
Dim T4
T1 = TextBox1
T2 = TextBox2
T3 = ComboBox1
T4 = ComboBox2
 
'Sheets("Temp3").Visible = True
'Sheets("Temp3").Select
'Cells.Select
'Selection.delete Shift:=xlUp
'Cells.Select
'Selection.delete Shift:=xlUp
'Cells.Select
'Selection.delete Shift:=xlUp
 
Sheets("Temp3").Cells.ClearContents
'Sheets("Temp").Visible = True
'Sheets("Temp").Select
'
'Range("A1").Select
'    Selection.AutoFilter
'    Selection.AutoFilter
 
Sheets("Temp").AutoFilterMode = False
Sheets("Temp").Range("A1").AutoFilter
Sheets("Temp").Range("A1").AutoFilter
  '  Sheets("temp").Range("A1").AutoFilter
 
 
 
   Dim LR As Long:
 
 
   LR = Sheets("temp").Range("A" & Rows.Count).End(xlUp).Row ' this code is to find the lastest cell with info
If T1 <> "" Then
'    ActiveSheet.Range("$A$1:L" & LR).AutoFilter Field:=1, Criteria1:="*" & T1 & "*"
'       Range("A1").Select
 
       Sheets("temp").Range("$A$1:L" & LR).AutoFilter Field:=1, Criteria1:="*" & T1 & "*"
 
Dim rng As Range
'Sheets("Temp").Range("A1").Select
'Dim rFoundCell As Range
'
' Set rFoundCell1 = Range("A1")
 ' With Sheets(temp)
'  Set rng = Cells.Find(What:=T1, After:=rFoundCell, LookIn:=xlFormulas, LookAt _
'        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
'        False, SearchFormat:=False)
 
' Error here !!!!! //////////////////////////
 
           Set rng = Sheets(temp).Cells.Find(What:=T1, After:=Range("A1"), _
                LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
                SearchDirection:=xlNext, MatchCase:=False)
'End With
If rng Is Nothing Then
 ' ActiveSheet.Range("$A$1:$K$46938").AutoFilter Field:=1
   Sheets("Temp").Range("$A$1:$K$999999").AutoFilter Field:=1
MsgBox "Not Found"
ListBox1.RowSource = ""
GoTo nope
 
End If
 
End If
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Welcome to MrExcel.

You need:

Rich (BB code):
Set rng = Sheets("temp").Cells.Find(What:=T1, After:=Range("A1"), _
 
Upvote 0
Great solution , thank you so much , although I didn’t re-enable the “With Sheets(“Temp”) “ because I got the same error on that sentence .<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,830
Members
449,190
Latest member
rscraig11

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