Using IF statement in Macro

Tim in Toronto

New Member
Joined
Nov 18, 2004
Messages
47
Hi Everyone,

I'm having a hard time figuring out a simple thing. Maybe I'm over thinking it. I simply want the macro to see if the word "FALSE" exists in column I, and if so then delete the column. Failing that, I just want it to return to cell A1. Tain't working. Any ideas on what I'm doing wrong here?

Range("I1").Select

If ActiveCell.Value = "FALSE" Then
Columns("I:I").Select
Selection.Delete Shift:=xlToLeft
Else
Range("A1").Select


End If

Tim :)
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi Tim
Your Macro is only checking Range "I1" for the FALSE
You need to check the entire range, eg, Range ("I1:I100).Select
It might be easier if you set your last used row and then did the search over that range.

Sub delete()
Dim r As Long, lrow As Long
Application.ScreenUpdating = False
lrow = Worksheets("sheetname").Cells(Rows.Count, "columnname").End(xlUp).Row
For r = lrow To 10 Step -1
If Range("I" & r).Value = "FALSE" Then
columns.entireColumn.Delete = True
End If
Next r
End Sub

Regards
Michael M
 
Upvote 0
Tim

See if this is it:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DelColI()<br>    <SPAN style="color:#00007F">Dim</SPAN> f <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    <SPAN style="color:#00007F">Set</SPAN> f = Range("I:I").Find(What:="FALSE")<br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> f <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> f.EntireColumn.Delete<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Hi Peter
Always an easier way to skin the cat isn't there.
You can see my code has a ways to go to get to yours, but if it works I s'pose

5mm rain in 2 months out here.!!
Regards
Michael M
 
Upvote 0
Peter,

If anyone hasn't told you lately, you're a genious :) Thank you so much! That does exactly what I want it to do.

Keep on Excelerating!
Tim :)
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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