If ... Then statement Compile Error

Twisted_Squeegie

New Member
Joined
Jan 4, 2018
Messages
6
Im getting a "Compile error: Expected: Then or GoTo" in an If ... Then statement.
My worksheet comes from a data logger that can record 20+ channels of data. The number of channels and channel numbers can change depending on the setup. If the channel is not being recorded the column header is labeled as "OFF" (with the quotes). Im trying to write a little snippet that will delete any columns that are not used.

col = 22
Do Until col = 2
if Cells(5, col).Value = " "OFF"" Then ' The value of the cell has a space then "OFF"
Columns(col).Delete
'do some stuff
Else
'do some other stuff
End If
col = col - 1
Loop
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try:
Code:
if Cells(5, col).Value = " OFF"
 
Upvote 0
How about
Code:
If Cells(5, Col).Value = Chr(34) & " OFF" & Chr(34) Then
 
Upvote 0
Try this.
Code:
col = 22
Do Until col = 2
    If Cells(5, col).Value Like "*OFF*" Then ' The value of the cell has a space then "OFF"
        Columns(col).Delete
        'do some stuff
    Else
        'do some other stuff
    End If

    col = col - 1

Loop
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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