HELP Debug

  • Thread starter Thread starter youu917
  • Start date Start date
Y

youu917

With Range("B1:B100")
Set FoundJurong = .Find(What:="Jurong", LookAt:=xlPart)
Set FoundTPY = .Find(What:="Toa", LookAt:=xlPart)
If Not FoundJurong Is Nothing Then

FoundJurongStart = FoundJurong.Row

For x = 1 To 100
Set FoundJurong = .FindNext(FoundJurong) 'jurong
FoundJurongEnd = FoundJurong.Row + 1 'jurong

Next
End If
If Not FoundTPY Is Nothing Then
FoundTPYStart = FoundTPY.Row


For x = 1 To 100

Set FoundTPY = .FindNext(FoundTPY) 'Toa Payoh
FoundTPYEnd = FoundTPY.Row + 1 'Toa Payoh
Next
End If
End With
Dim r As Variant
For r = FoundJurongStart To FoundJurongEnd 'jurong
If TextBox1.Value = Sheet6.Cells(r, 1).Value Then
Label1.Visible = True
End If
Next
For r = FoundTPYStart To FoundTPYEnd 'TPY
If TextBox1.Value = Sheet6.Cells(r, 1).Value Then
Label3.Visible = True
End If
Next
End Sub

It is a search button that will search the data in under 2 groups:
'Jurong' and 'Toa'.When clicked the search button, it will search the
data( keyed in textbox1) in 'sheet6' and then change the visibility of
labels.if the data is under 'jurong' group, label 1 will become
visible, if data is under 'Toa' group, label3 will become visible.
I'm wondering why the code above cannot run properly but if i only
search for 1 part( i.e: i delete all the codes regarding 'TPY, and
search the data in 'Jurong' group), it will work properly.
 
With Range("B1:B100")
Set FoundJurong = .Find(What:="Jurong", LookAt:=xlPart)
If Not FoundJurong Is Nothing Then
FoundJurongStart = FoundJurong.Row
For x = 1 To 100
Set FoundJurong = .FindNext(FoundJurong) 'jurong
FoundJurongEnd = FoundJurong.Row + 1 'jurong
Next
End If
Set FoundTPY = .Find(What:="Toa", LookAt:=xlPart)
If Not FoundTPY Is Nothing Then
FoundTPYStart = FoundTPY.Row
For x = 1 To 100
Set FoundTPY = .FindNext(FoundTPY) 'Toa Payoh
FoundTPYEnd = FoundTPY.Row + 1 'Toa Payoh
Next
End If
End With
Dim r As Variant
For r = FoundJurongStart To FoundJurongEnd 'jurong
If TextBox1.Value = Sheet6.Cells(r, 1).Value Then
Label1.Visible = True
End If
Next
For r = FoundTPYStart To FoundTPYEnd 'TPY
If TextBox1.Value = Sheet6.Cells(r, 1).Value Then
Label3.Visible = True
End If
Next
End Sub
 
With Range("B1:B100")
Set FoundJurong = .Find(What:="Jurong", LookAt:=xlPart)
If Not FoundJurong Is Nothing Then
FoundJurongStart = FoundJurong.Row
For x = 1 To 100
Set FoundJurong = .FindNext(FoundJurong) 'jurong
FoundJurongEnd = FoundJurong.Row + 1 'jurong
Next
End If
Set FoundTPY = .Find(What:="Toa", LookAt:=xlPart)
If Not FoundTPY Is Nothing Then
FoundTPYStart = FoundTPY.Row
For x = 1 To 100
Set FoundTPY = .FindNext(FoundTPY) 'Toa Payoh
FoundTPYEnd = FoundTPY.Row + 1 'Toa Payoh
Next
End If
End With
Dim r As Variant
For r = FoundJurongStart To FoundJurongEnd 'jurong
If TextBox1.Value = Sheet6.Cells(r, 1).Value Then
Label1.Visible = True
End If
Next
For r = FoundTPYStart To FoundTPYEnd 'TPY
If TextBox1.Value = Sheet6.Cells(r, 1).Value Then
Label3.Visible = True
End If
Next
End Sub











- ÏÔʾÒýÓõÄÎÄ×Ö -

Thank you very much
 
Can anyone tell me how to do this kind of programming? i made sure it
can work under 1 search, then i tried to copy the code and make a
little change to search for another groups of words. however, it
always occur error and didn't work properly. Can anyone give me a
suggestion on how to do the programming so that if i want to add
another new search, i can just copy the old code and make a little
change and it will work.
thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top