Partial match in VBA

Bo2DK

New Member
Joined
Aug 12, 2014
Messages
11
Hi,

I'm trying to get Excel to run through a worksheet and copy those rows which match the criterias that has been chosen in a userform. The only thing that i can't get to work, is the month value since the ref. cell is in the "dd-mmm-yy", and my vba code can only find the row if I change the format to "mmm" which isn't acceptable (in the userform you can which month to copy).

I do have most of the code, I think its only the part in bold that needs to be changed so that it looks for a partial match.

Code:
Month = SelMonth.Value
...
If Range(ColumnMon & CStr(LSearchRow)).Value = [B]Month[/B] Then
So how do I get Excel to find eg. "Jan" in a cell with the date format that looks like eg "11-Jan-15"?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi - maybe like this:

Rich (BB code):
If Format(Range(ColumnMon & CStr(LSearchRow)).Value, "mmm") = Month Then
 
Upvote 0
You should try using a different variable name, Month is a reserved word in VBA, try again with sMonth for example.
Thanks for the input, I've changed the variable name, but it doesn't change the result.
 
Upvote 0
If difficult to provide much more advice - you've only posted one line of code. You probably need to step though the code and do a little de-bugging.

FYI - this is how I tested it.

Code:
Sub Test()
Dim sMonth As String, ColumnMon As String, LSearchRow As Long


sMonth = "Jun"
ColumnMon = "A"


For LSearchRow = 1 To 5
    If Format(Range(ColumnMon & CStr(LSearchRow)).Value, "mmm") = sMonth Then
        MsgBox ColumnMon & LSearchRow & " is Match"
            Else
        MsgBox "No Match"
    End If
Next LSearchRow


End Sub



Excel 2012
ABC
1DateCommentMsgbox Result
201-Mar-2015< Formatted as dd-mmm-yyyyNo Match
301-Apr-2015No Match
401-May-2015No Match
501-Jun-2015A5 is Match
601-Jul-2015No Match
Sheet1
 
Upvote 0

Forum statistics

Threads
1,207,259
Messages
6,077,348
Members
446,279
Latest member
hoangquan2310

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