ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,890
- Office Version
- 2007
- Platform
- Windows
The code in question is supplied below.
On my worksheet i have customers names in column B
I start by opening my userform & i enter the customers name in TextBox2 Example TOM JONES.
The code looks down column B on my worksheet for all the TOM JONES.
Each time TOM JONES makes a purchase 3 digits are added to the end of his name,So lets say in this case the search has found TOM JONES 001 & TOM JONES 002
Back to userform now, When i leave TextBox2 on this occurance 003 will be added to TOM JONES in TextBox2, I complete all the other TextBoxes & the values are sent to my worksheet.
This all works fine & never an issue.
Now at present the last row with values on my worksheet is 2316
The issue i have is that one particular customer has made numerous purchases overtime & his 3 digits are now 105
The issue is when i go to leave TextBox2 the search of which i assume looks from row 2316 right back until row 7 is now taking some time before his next 3 digits are added to his name.
Im experiencing lag with this one customer.
Can we alter the code below to speed things up or do you think the code just needs to be altered for another to overcome this lag
First time customers or customers that only have 002 003 004 etc after their name doesnt seem to be an issue & leaving TextBox2 is pretty much no problem.
This customers buys from me pretty much every month so maybe restrict & only this customer to have the code search maybe back the last 100 rows each time.
So maybe some kind of IF code for JOES BLOGGS etc etc to check back 100 rows or Exit Sub if its another customer, Just a thought
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim fndRng As Range
Dim findString As String
Dim i As Integer
Dim wsPostage As Worksheet
findString = Me.TextBox2.Value
If Len(findString) = 0 Then Exit Sub
Set wsPostage = ThisWorkbook.Worksheets("POSTAGE")
i = 1
Do
Set fndRng = Nothing
Set fndRng = wsPostage.Range("B:B").Find(What:=findString & Format(i, " 000"), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not fndRng Is Nothing Then
i = i + 1
Cancel = True
End If
Loop Until fndRng Is Nothing
Me.TextBox2.Value = findString & Format(i, " 000")
Cancel = False
End Sub
On my worksheet i have customers names in column B
I start by opening my userform & i enter the customers name in TextBox2 Example TOM JONES.
The code looks down column B on my worksheet for all the TOM JONES.
Each time TOM JONES makes a purchase 3 digits are added to the end of his name,So lets say in this case the search has found TOM JONES 001 & TOM JONES 002
Back to userform now, When i leave TextBox2 on this occurance 003 will be added to TOM JONES in TextBox2, I complete all the other TextBoxes & the values are sent to my worksheet.
This all works fine & never an issue.
Now at present the last row with values on my worksheet is 2316
The issue i have is that one particular customer has made numerous purchases overtime & his 3 digits are now 105
The issue is when i go to leave TextBox2 the search of which i assume looks from row 2316 right back until row 7 is now taking some time before his next 3 digits are added to his name.
Im experiencing lag with this one customer.
Can we alter the code below to speed things up or do you think the code just needs to be altered for another to overcome this lag
First time customers or customers that only have 002 003 004 etc after their name doesnt seem to be an issue & leaving TextBox2 is pretty much no problem.
This customers buys from me pretty much every month so maybe restrict & only this customer to have the code search maybe back the last 100 rows each time.
So maybe some kind of IF code for JOES BLOGGS etc etc to check back 100 rows or Exit Sub if its another customer, Just a thought
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim fndRng As Range
Dim findString As String
Dim i As Integer
Dim wsPostage As Worksheet
findString = Me.TextBox2.Value
If Len(findString) = 0 Then Exit Sub
Set wsPostage = ThisWorkbook.Worksheets("POSTAGE")
i = 1
Do
Set fndRng = Nothing
Set fndRng = wsPostage.Range("B:B").Find(What:=findString & Format(i, " 000"), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not fndRng Is Nothing Then
i = i + 1
Cancel = True
End If
Loop Until fndRng Is Nothing
Me.TextBox2.Value = findString & Format(i, " 000")
Cancel = False
End Sub
Last edited: