Macro to Select Cells containing Text

seenai

Board Regular
Joined
Mar 31, 2013
Messages
54
Hi,

I have a Range that contains Text like below :
Date
Time
Sr No
Associate

I need a macro to select CELLS that match the any of the words.
Else need to select Cell A1.

Request your help to create a macro.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try to insert the line
VBA Code:
a = Array("Date", "Time", "Sr No", "Associate")
Sheets("700C Test").Select
For i = 1 To 100
 
Upvote 0
Try to insert the line
VBA Code:
a = Array("Date", "Time", "Sr No", "Associate")
Sheets("700C Test").Select
For i = 1 To
[/QUOTE]
Hi,

Alternatively I trying another code.

Selection.Find(What:="JobOrderNo", After:=ActiveCell, LookAt:=xlWhole).Activate
On Error Resume Next
ActiveCell.EntireColumn.Delete
Selection.Find(What:="ModelDesc", After:=ActiveCell, LookAt:=xlWhole).Activate

On Error Resume Next

The above code first searches for "JobOrder"
If not available, I do not want to execute statement
ActiveCell.EntireColumn.Delete

Help me if possible.
 
Upvote 0
Perhaps
VBA Code:
Selection.Find(What:="JobOrderNo", After:=ActiveCell, LookAt:=xlWhole).Activate
On Error GoTo 1
ActiveCell.EntireColumn.Delete
1 Selection.Find(What:="ModelDesc", After:=ActiveCell, LookAt:=xlWhole).Activate
On Error GoTo 2
ActiveCell.EntireColumn.Delete
2 Selection.Find(What:="xxxxx", After:=ActiveCell, LookAt:=xlWhole).Activate
ActiveCell.EntireColumn.Delete
On Error GoTo 3



3 ....
 
Upvote 0
Still this working
Told you to edit the line
VBA Code:
  a = Array("Date", "Time", "Sr No", "Associate", "JobOrderNo", "ModelDesc")
VBA Code:
Sub testr()
    Dim rg As Range
    Dim a As Variant
    Dim i, ii
    a = Array("Date", "Time", "Sr No", "Associate", "JobOrderNo", "ModelDesc")
    For i = 1 To 100
        For ii = 0 To UBound(a)
            If Cells(1, i) = a(ii) Then
                If rg Is Nothing Then
                    Set rg = Cells(1, i)
                Else
                    Set rg = Union(rg, Cells(1, i))
                End If: End If
        Next: Next
    rg.EntireColumn.Delete
End Sub
 
Upvote 0
Still this working
Told you to edit the line
VBA Code:
  a = Array("Date", "Time", "Sr No", "Associate", "JobOrderNo", "ModelDesc")
VBA Code:
Sub testr()
    Dim rg As Range
    Dim a As Variant
    Dim i, ii
    a = Array("Date", "Time", "Sr No", "Associate", "JobOrderNo", "ModelDesc")
    For i = 1 To 100
        For ii = 0 To UBound(a)
            If Cells(1, i) = a(ii) Then
                If rg Is Nothing Then
                    Set rg = Cells(1, i)
                Else
                    Set rg = Union(rg, Cells(1, i))
                End If: End If
        Next: Next
    rg.EntireColumn.Delete
End Sub
Hi,

It is GREAT & PERFECT.

Thank you so much for help.

Srinivasa Rao(y)?
 
Upvote 0
You are welcome
And thank you for the feedback
Be happy & safe
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
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