VBA IF/THEN not working

EMcK01

Board Regular
Joined
Jun 14, 2015
Messages
125
Hi,

Struggling with this and not sure why.
I want to look through the range of cells and offset any cell with essentially a date in it. ie. B3 contains Saturday 26 August 2017, B11 contains Sunday 27 August 2017. There is no regular pattern to this so need to look within all cells in the range. As it covers multiple dates, days, months and years thought searching for *day* would be the simplest solution.

Stepping through the code it appears to see the values in all cells however it doesn't then do the copy offset and clear when it finds *day* within the cell

Code:
       Set rngA = Sheets(wsName).Range("B3:B" & numRows)       
           For Each cell In rngA
            If cell.Value = "*day*" Then              
              cell.Copy cell.Offset(0, 5)
              cell.Clear
            End If
        Next cell

Any help on this would be appreciated.

Thanks,
EMcK
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The = operator does not use wildcards so you are looking for the literal text "*day*" which clearly isn't there. You can use Instr or Like instead:

Code:
If cell.Value Like "*day*" Then

or:

Code:
If Instr(1, cell.value, "day", vbtextcompare) <> 0 then
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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