If CurrentCell.Value *CONTAINS*

bschulze

Active Member
Joined
Jun 2, 2005
Messages
289
I have been searching for this but my search criteria must be way off. I am trying to find out if it is possible use "*" for contains in this type of function. I have used "=" and "<>" however I now need to use contains and I am not able to figure this out. This is an example of what I am looking for:

Code:
            If CurrentCell.Value = "*Total*" Then
                   CopyRange.Select
                   Selection.Copy
                   ColumnCell.Select
                   ActiveSheet.Paste
            End If

The problem is that "Total" is buried in the cell and not buried in a consistent mannor. Any help would be great or if someone knows of a link. Thanks in advance.
 
Thanks for the "UCase" tip, I have never used that function before...It works great....thanks again
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi bschulze

You can also tell vba that you want to perform a textual comparison.

If you want that for all the comparisons in the module just write the compare option at the top of the module before any procedure.

Code:
Option compare Text
...
...
If InStr(a.Value, "totals") Then
...

Another possibility is if you want this option to be valid for just a specific call of Instr. In this case use the optional arguments as I wrote in my post

Code:
If InStr(1, a.Value, "totals", vbTextCompare) Then

Any of the 2 will solve your problem.

HTH
PGC
 
Upvote 0
Thanks for all the good suggestions. I can not get this last part.


Code:
Set CurrentCell = Range("A2")
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Do While CurrentCell <> Range("A" & LastRow)

I want the operation to run until it gets to the last cell (LastRow) of the data. I would use isEmpty except there are Blank Rows that I need until this opertion runs. I cant figure it out....What happens when I run this now is it skips over the entire Do While process.
 
Upvote 0
Hi

You're comparing values in the cells, not the cells themselves (with your code). Maybe you can use this:

Code:
Set CurrentCell = Range("A2") 
LastRow = Range("A" & Rows.Count).End(xlUp).Row 
Do While CurrentCell.Row < LastRow

Best regards

Richard
 
Upvote 0
If you're looking to get a bunch of cells here, better to loop through the target range vis Find, I think.
 
Upvote 0
I will check out the "Find" function. This would probally work out better for me since I am really only concerned with a couple thousand rows, but looking at upwards of 40,000. This would speed up the macro considerably...I was looking for a quick temporary solution, and I had some of this code handy....thanks for the suggestion.
 
Upvote 0
If they all have the same value in them (these couple of thousand cells out of 40000) then the absolute quickest way bar none would be to use Autofilter. If you need help to use this feature, post back!

Richard
 
Upvote 0

Forum statistics

Threads
1,215,886
Messages
6,127,586
Members
449,386
Latest member
owais87

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