VBA Offset

jamada

Active Member
Joined
Mar 23, 2006
Messages
323
I have a spread sheet that the user enters 3 characters in B2 of a name, then the code will determine out of 35,000 rows with names in Column B how many match the 3 consecutive chracters, all other rows that dont match will hide.

My issue is, that the code seams to find the 3 leters only when there in the middle of a name, and will not identify all other simularities where the 3 letters are at the begining of the name, or at lerast not in all cases.

I adjusted the "Set tempCell = .Columns(2)." to (1) and that worked great but caused other problems.

Help is much appreciated ..........tks gg

lastrow = .Cells(Rows.Count, 2).End(xlUp).Row
Set tempCell = .Range("B:B").Find(what:=Left(.Range("B2").Value, 3), After:=.Range("B2"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If tempCell Is Nothing Then
MsgBox "Not found"
Exit Sub
Else
Set foundCell = tempCell
Range(.Range("B3"), foundCell.Offset(-1, 0)).EntireRow.Hidden = True

End If
Do
Set tempCell = .Columns(2).FindNext(After:=foundCell)
If foundCell.Row >= tempCell.Row Then Exit Do
Range(foundCell.Offset(1, 0), tempCell.Offset(-1, 0)).EntireRow.Hidden = True
Set foundCell = tempCell
Loop
Range("A" & foundCell.Row + 1 & ":A" & lastrow).EntireRow.Hidden = True
End With
End Sub
 
Hi Stan

Thanks for your solution.

Option Explecit................hmmmmmmmmmm Way Beyond my novice ability I think 9Know) I have tried several ways to place this into the formula unsuccesfully, I did manage to find and tick off 'Require Variable declaration".........but stumped on where to include Option expecit.


tks g
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,216,099
Messages
6,128,816
Members
449,469
Latest member
Kingwi11y

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