macro to automatically select certain cells.

topi1

Board Regular
Joined
Aug 6, 2014
Messages
248
Office Version
  1. 2010
I have a worksheet called "Home". Some of the cells from A1 to Z50 can be populated with the word "Yes". Is there a macro which when activated will only select (click) cells in the range which contain the word "Yes".

Thanks I advance for all your help.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Code:
Sub Select_Yes()

For Each cell In Range("A1:Z50")
    If cell.Value = "Yes" Then
        sel = sel & cell.Address & ","
    End If
Next

sel = Left(sel, Len(sel) - 1)

Range(sel).Select

End Sub
 
Upvote 0
That is perfect. You are a savior. Thank you so much for the help all of you provide.
 
Upvote 0
How do I add the above code at the end of the following macro and make it a part of that macro?
Thanks.





Sub STARTNew()
'
' STARTNew Macro
'

'


Range("B64").Select
Application.CutCopyMode = False
Selection.Copy

Range("E25,J25,L25").Select
Range("L25").Activate
ActiveSheet.Paste
Range("E29:L30").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("B28").Select
Selection.Copy
Range("N25:N28").Select
ActiveSheet.Paste

Range("B9").Select
Application.CutCopyMode = False
Selection.Copy
Range("O18,O21").Select
Range("O21").Activate
ActiveSheet.Paste
Range("O4:O15").Select
Range("O15").Activate
Application.CutCopyMode = False
Selection.ClearContents

Range("B30:B33").Select
Selection.Copy

Range("D19").Select
ActiveSheet.Paste

Range("B35:B47").Select
Application.CutCopyMode = False
Selection.Copy

Range("D3").Select
ActiveSheet.Paste

Range("B4").Select
Application.CutCopyMode = False
Selection.Copy
Range("J1").Select
ActiveSheet.Paste

End Sub
 
Upvote 0
Just copy my code and paste it into your module as new sub. Then just add this line at the end of your code:

Code:
Call Select_Yes
 
Upvote 0
Hi,
I think I did what you suggested. Here is what i get. However, I get the following error.
Thanks.
Compile Error:
Sub or Function not found

Sub STARTNew()
'
' STARTNew Macro
'
'



Range("B64").Select
Application.CutCopyMode = False
Selection.Copy

Range("E25,J25,L25").Select
Range("L25").Activate
ActiveSheet.Paste
Range("E29:L30").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("B28").Select
Selection.Copy
Range("N25:N28").Select
ActiveSheet.Paste

Range("B9").Select
Application.CutCopyMode = False
Selection.Copy
Range("O16,O20").Select
Range("O20").Activate
ActiveSheet.Paste
Range("O4:O15").Select
Range("O15").Activate
Application.CutCopyMode = False
Selection.ClearContents

Range("B30:B33").Select
Selection.Copy

Range("D19").Select
ActiveSheet.Paste

Range("B35:B47").Select
Application.CutCopyMode = False
Selection.Copy

Range("D3").Select
ActiveSheet.Paste

Range("B4").Select
Application.CutCopyMode = False
Selection.Copy
Range("J1").Select
ActiveSheet.Paste
For Each cell In Range("D1:Z50")
If cell.Value = "Yes" Then
sel = sel & cell.Address & ","
End If
Next
sel = Left(sel, Len(sel) - 1)
Range(sel).Select
Call Select_Yes

End Sub
 
Upvote 0
There are two ways:

Code:
Sub STARTNew()
'
' STARTNew Macro
'
'
    
    
    
    Range("B64").Select
    Application.CutCopyMode = False
    Selection.Copy
    
    Range("E25,J25,L25").Select
    Range("L25").Activate
    ActiveSheet.Paste
    Range("E29:L30").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("B28").Select
    Selection.Copy
    Range("N25:N28").Select
    ActiveSheet.Paste
    
    Range("B9").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("O16,O20").Select
    Range("O20").Activate
    ActiveSheet.Paste
    Range("O4:O15").Select
    Range("O15").Activate
    Application.CutCopyMode = False
    Selection.ClearContents
   
    Range("B30:B33").Select
    Selection.Copy
    
    Range("D19").Select
    ActiveSheet.Paste
    
    Range("B35:B47").Select
    Application.CutCopyMode = False
    Selection.Copy
    
    Range("D3").Select
    ActiveSheet.Paste
   
   Range("B4").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("J1").Select
    ActiveSheet.Paste

For Each cell In Range("D1:Z50")
    If cell.Value = "Yes" Then
        sel = sel & cell.Address & ","
    End If
Next
sel = Left(sel, Len(sel) - 1)
Range(sel).Select

End Sub

or

Code:
Sub STARTNew()
'
' STARTNew Macro
'
'
    
    
    
    Range("B64").Select
    Application.CutCopyMode = False
    Selection.Copy
    
    Range("E25,J25,L25").Select
    Range("L25").Activate
    ActiveSheet.Paste
    Range("E29:L30").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("B28").Select
    Selection.Copy
    Range("N25:N28").Select
    ActiveSheet.Paste
    
    Range("B9").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("O16,O20").Select
    Range("O20").Activate
    ActiveSheet.Paste
    Range("O4:O15").Select
    Range("O15").Activate
    Application.CutCopyMode = False
    Selection.ClearContents
   
    Range("B30:B33").Select
    Selection.Copy
    
    Range("D19").Select
    ActiveSheet.Paste
    
    Range("B35:B47").Select
    Application.CutCopyMode = False
    Selection.Copy
    
    Range("D3").Select
    ActiveSheet.Paste
   
   Range("B4").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("J1").Select
    ActiveSheet.Paste

Call Select_Yes

End Sub



Sub Select_Yes()

For Each cell In Range("A1:Z50")
    If cell.Value = "Yes" Then
        sel = sel & cell.Address & ","
    End If
Next

sel = Left(sel, Len(sel) - 1)

Range(sel).Select

End Sub
 
Upvote 0
Too bad. It did not work. I get runtime error # 13. (Type mismatch). When I click on debug, it takes me to the following macro which is part of the worksheet.



Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Value = "No" Then
Target = "Yes"
ElseIf Target.Value = "Yes" Then
Target = "No"
End If
End Sub
 
Upvote 0
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

For Each cell In Target
    If cell.Value = "No" Then
        cell.Value = "Yes"
    ElseIf cell.Value = "Yes" Then
        cell.Value = "No"
    End If
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

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