vba compare script help

jonathan_smithey

New Member
Joined
Mar 31, 2009
Messages
9
Hi guys,

I've written a bit of VBA script within Excel that searches through data within one column of an excel spreadsheet and where a specific word is named in that column (this variable is data that is entered in a specific cell), copy several cells from that row to a different worksheet. This works well but it has a limitation - it only searches for words that exactly match the case of the word(s) entered. i.e if the word "The" was entered as the search criteria only rows containing the word "The" would be returned. Rows with the word "THE" or "the" would not be returned. Other than converting everything to upper case prior to the search, is there any way that the code can be made to seach "case insensitive"?

The code that I'm using is:
(the variable "SearchWord" is the criteria that's entered in a cell on a worksheet)

'this will only search upto row 1000
For sRow = 1 To Range("E1000").End(xlUp).Row
If Cells(sRow, SearchColumn) Like "*" & SearchWord & "*" Then
sCount = sCount + 1
dRow = dRow + 1
Cells(sRow, "A").Copy Destination:=DestSheet.Cells(dRow, "A")
Cells(sRow, "B").Copy Destination:=DestSheet.Cells(dRow, "B")
Cells(sRow, "C").Copy Destination:=DestSheet.Cells(dRow, "C")
Cells(sRow, "D").Copy Destination:=DestSheet.Cells(dRow, "D")
Cells(sRow, "E").Copy Destination:=DestSheet.Cells(dRow, "E")
End If
Next sRow

Any help/assistance would be greatly appreciated
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Hello and welcome to MrExcel.

Try putting this at the top of the module, before any Subs.

Code:
Option Compare Text
 
Upvote 0

jonathan_smithey

New Member
Joined
Mar 31, 2009
Messages
9
Magic - it works...

Thanks for the super, speedy response.

Is it easy for you to explain what that command does so that I can better understand for next time?
 
Upvote 0

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Well I could explain but why not click in the word Like in your code and press F1 to get Microsoft's explanation :)
 
Upvote 0

Forum statistics

Threads
1,191,350
Messages
5,986,152
Members
440,006
Latest member
efcornell

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
Top