VBA if x like... returning false

taikvei

New Member
Joined
Nov 29, 2018
Messages
14
Hi there,

I have the below bit of code. In my head, it should loop through columns 1 to 52 of row 8 of the spreadsheet assigned to cTeam, and return True if the value is like "tel".

The values in those cells are Contact Tel. Contact Tel. 2 Home Tel. Home Tel. 2 etc., but the Like operator keeps returning false - am I doing it wrong somehow? I've tried having it as "*Tel*" as well as what it is now, but it hasn't helped. I've stepped through all 52 iterations with F8 and it hasn't picked up any of the columns with the Tels

Code:
With cTeam

    For logCol = 1 To 52 Step 1
    colLetter = Split(Cells(1, logCol).Address, "$")(1)
        If Cells(8, logCol).Value Like "*" & "Tel" & "*" Then
        cTeam.Range(colLetter & "8" & ":" & logCol).SpecialCells(xlCellTypeVisible).Copy
        cSheet.Cells(1, cSheetCol).PasteSpecial Paste:=xlPasteValues
        cSheetCol = cSheetCol + 1
        End If
    
    Next logCol
End With
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I'm sorry - I'm pretty new at VBA and have done most of everything via googling/macro recorder and gluing stuff together. Could you explain why I need the dots? It seems to be working without them?
 
Upvote 0
Any idea why it never popped up with an error before? which is why I thought the issue was with the Like operator?
It depends where you put the code. In a standard module, Cells(...) refers to the active sheet and .Cells(...) refers to the With cTeam sheet. So if the cTeam sheet isn't active Cells(...) is looking at the wrong sheet. In a sheet module, Cells(...) refers to that sheet, regardless of the active sheet.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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