Find text across row 1 and highlight those columns

Bret1

Board Regular
Joined
Jun 14, 2013
Messages
199
Is there a way I can search a selected area for text containing ":50" in row 1 and have it highlight each full column that contains it so I can then delete all those columns and shift to the left?
 
In any case Try this macro:

VBA Code:
Sub selectcolumns()
  Dim j As Long
  Dim rng As Range
  For j = 1 To Cells(1, Columns.Count).End(1).Column
    If Not (Cells(1, j).Text Like "*:00*" Or Cells(1, j).Text Like "*:30*") Then
      If rng Is Nothing Then Set rng = Cells(1, j) Else Set rng = Union(rng, Cells(1, j))
    End If
  Next
  If Not rng Is Nothing Then rng.EntireColumn.Select
End Sub
I think that Macro will work! But.... Could you make it so that it only searches and selects columns within a range of highlighted columns? It picked out all the columns I want to delete, but it also included some columns outside the column range I want to keep. thanks! ......Or if not that, maybe only search columns higher (to the right) of "X"?
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
maybe only search columns higher (to the right) of "X"?
Please include all those details from the original post.


Try this
VBA Code:
Sub selectcolumns()
  Dim j As Long
  Dim rng As Range
  For j = Columns("Y").Column To Cells(1, Columns.Count).End(1).Column
    If Not (Cells(1, j).Text Like "*:00*" Or Cells(1, j).Text Like "*:30*") Then
      If rng Is Nothing Then Set rng = Cells(1, j) Else Set rng = Union(rng, Cells(1, j))
    End If
  Next
  If Not rng Is Nothing Then rng.EntireColumn.Select
End Sub

🧙‍♂️
 
Upvote 0
Solution
Please include all those details from the original post.


Try this
VBA Code:
Sub selectcolumns()
  Dim j As Long
  Dim rng As Range
  For j = Columns("Y").Column To Cells(1, Columns.Count).End(1).Column
    If Not (Cells(1, j).Text Like "*:00*" Or Cells(1, j).Text Like "*:30*") Then
      If rng Is Nothing Then Set rng = Cells(1, j) Else Set rng = Union(rng, Cells(1, j))
    End If
  Next
  If Not rng Is Nothing Then rng.EntireColumn.Select
End Sub

🧙‍♂️
I think that will work PERFECT! I'll spend some time reviewing and working on it now. But it looks great. Thanks so much!
 
Upvote 0
I think that will work PERFECT! I'll spend some time reviewing and working on it now. But it looks great.
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,215,088
Messages
6,123,056
Members
449,091
Latest member
ikke

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