Unable to search using xlPart on xlWhole

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,224
Office Version
  1. 2007
Platform
  1. Windows
Evening,

Im using the code below but it will only work if xlWhole is used.
Im needing it to work using xlPart

Do you see wjhy this should happen

Rich (BB code):
Private Sub CommandButton1_Click()
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   Dim Fnd As Range
   Dim i As Long, Qty As Long, Nrow As Long
   Dim Str As String
   
   Set Ws1 = Sheets("DETAILS")
   Set Ws2 = Sheets("HELPERSHEET")
   Set Fnd = Ws1.Range("A" & Rows.Count)
   Str = TextBoxCUSTOMER.Value
   
   If Str = "" Then Exit Sub
   Ws2.Cells.Clear
   
   Qty = WorksheetFunction.CountIf(Ws1.Columns("A"), Str)
   
   Nrow = 2
   For i = 1 To Qty
      Nrow = Nrow + 1
      Set Fnd = Ws1.Range("A:A").Find(Str, Fnd, , xlWhole, xlByRows, xlNext, False, , False)
      Ws2.Cells(Nrow, 1).Resize(, 8).Value = Fnd.Offset(, 0).Resize(, 8).Value
   Next i
End Sub
 

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.
Guessing shot since you have not posted an example, in my opinion the problem arises from here: Str = TextBoxCUSTOMER.Value
If you aren't using wildcards you wouldn't get over this: Qty = WorksheetFunction.CountIf(Ws1.Columns("A"), Str) since it will only count the "full" words to be found by value of Str.
since it will only count the "full" words to be found by value of Str.
Therefor xlPart will be useless.
 
Upvote 0
Solution
You are correct.
I found & used a different line of code & now all ok
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,985
Members
448,935
Latest member
ijat

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