Active Cell to Run Macro

Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Hello!

In columns B2:B20 I have the Names of all the other sheets in the workbook and each sheet has information in it.

What I want to be able to do is click on, let's say B4 and it references the appropriate Sheet name and pulls that data range to L2 and continue that process for each B:B column title I click on.

I got it work once but can't seem to replicate it again. Any help would be greatly appreciate!

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Selection, Range("B2")) Is Nothing Then
        If Selection.Count = 1 Then Exit Sub
        If Selection.Value = "" Then Exit Sub
        Sheets(Range("B2").Value).Range("A1:U50").Copy Range("L2")
    End If
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
How about
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Value = "" Then Exit Sub
   If Not Intersect(Target, Range("B2:B20")) Is Nothing Then
      Sheets(Target.Value).Range("A1:U50").Copy Range("L2")
   End If
End Sub
 
Upvote 0
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B2:B20")) Is Nothing Then
        If Target.Cells.Count > 1 Then Exit Sub
        If Target.Value = "" Then Exit Sub
        Sheets(Target.Value).Range("A1:U50").Copy Range("L2")
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,743
Members
449,094
Latest member
dsharae57

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