Like expression cause performance problem

SHIRLEY YEUNG

New Member
Joined
Jan 20, 2011
Messages
8
Here is part of the codes. I want to use the statements to check if the email subject matches to any of the subjects saved in column K. It can execute without problem. However, email subject can vary from time to time, but still it should contains some key words unchanged. So I tried to use Like instead of = . But when I execute it hanged my Excel. Please give me some advice. Thanks!

Range("K2").Select
For Each A In Range(Selection, Selection.End(xlDown))
subjectVal = A.Value

If UCase(OSubject) = UCase(subjectVal) Then
ActiveCell.Offset(0, -7).Range("A1").Select
------------------------------------------------------
Range("K2").Select
For Each A In Range(Selection, Selection.End(xlDown))
subjectVal = A.Value

If UCase(OSubject) Like "*" & UCase(subjectVal) & "*" Then
ActiveCell.Offset(0, -7).Range("A1").Select
 
Hi Norie,

Thanks! Your codes works! :cool:
Yes, the codes are being run in Excel. I do not need
Code:
Set wb = ThisWorkbook

I have changed the codes as below.

Code:
Set Rng = Workbooks(ProcessorName).Sheets("XrefEmail").Range("C2")
For Each A In Range(Rng, Workbooks(ProcessorName).Sheets("XrefEmail").Cells(Rows.Count, Rng.Column).End(xlUp))
    senderval = A.Value
    subjectVal = A.Offset(0, 8).Value
 
  If (UCase(senderval) = UCase(TempOsender)) And (UCase(OSubject) Like "*" & UCase(subjectVal) & "*") Then
    A.Offset(0, 1).Select
 
    ArchiveNameTag = ActiveCell.Text
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Well glad it works but why don't you need Set wb=ThisWorkbook?

You don't have to use it but it could make like a lot easier, it might even extend the lifetime of your keyboard.:)

Also, why are you still using Select/ActiveCell when it's not needed - that could even have been the root of the problem in the first place.

If you want to put the value in the cell to the right of A in ArchiveTag you can just use this.
Code:
ArchiveTag =A.Offset(,1).Text
 
Last edited:
Upvote 0
Yes I will change it. I never touched the vba before. I was just using my limited knowledge to modify the codes written by other. I should practise more in the future to built up the technique. :)
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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