bobkap
Active Member
- Joined
- Nov 22, 2009
- Messages
- 323
- Office Version
- 365
- Platform
- Windows
- Mobile
- Web
This seems ridiculously easy, but I cannot figure it out after many tries.
Scenario: I have approx 35 columns (and rows of course) of data. I want to sequence through each column and delete any columns that meet a certain condition. Here's one of my many attempts that do not work. Example of why it doesn't work: Say column 3 meets the condition and gets deleted. What was col #4 now becomes #3 but I've gone past #3 now so it does not test col #3 for the condition. Somehow, I need to reset the counter so that it address this. Any help would be greatly appreciated.
counter = 1
For counter = counter To finalcol
If Cells(1, counter) <> "Phone" Then
Columns(counter).Delete
counter = counter - 1
End If
Next counter
Scenario: I have approx 35 columns (and rows of course) of data. I want to sequence through each column and delete any columns that meet a certain condition. Here's one of my many attempts that do not work. Example of why it doesn't work: Say column 3 meets the condition and gets deleted. What was col #4 now becomes #3 but I've gone past #3 now so it does not test col #3 for the condition. Somehow, I need to reset the counter so that it address this. Any help would be greatly appreciated.
counter = 1
For counter = counter To finalcol
If Cells(1, counter) <> "Phone" Then
Columns(counter).Delete
counter = counter - 1
End If
Next counter