Run a Macro based on a cell value

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
18
Office Version
  1. 2010
Platform
  1. Windows
I have a summary tab where i want to run macros depending on what is selected in a drop down list to compare two other data tabs. The data tabs are called 'A', 'B', 'C', 'D', 'E' and 'F', and the data in each tab is in the same cells and format, just different values. I want to have two drop down lists, Compare Tab 1: with drop down list A-F, and Compare Tab 2: with drop down list A-F.

Once the two tab names are selected, I want to be able to run a macro whereby it just looks at the tab name that has been selected and then pulls in the data to the summary tab. So I need to know if i can declare the multiple tab names and then the macro looks up which one has been selected, without the need of repeating the macro for every tab name.
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Puertorekinsam

Active Member
Joined
Oct 8, 2005
Messages
287
I'm not 100% sure what you are asking for... but I think what you want is something like the following..

Let's assume your first drop down value is in Sheet1 cells A1 and the second is in Sheet1 cells A2

you can use code like this
Code:
dim ws1 as worksheet
dim ws2 as workseet

set ws1= thisworkbook.sheets(sheet1.cells(1,1))
set ws2= thisworkbook.sheets(sheet1.cells(2,1))

then in your actual code you just refer to the sheets like

Code:
if ws1.cells(1,1)=ws2.cells(1,1) Then
     msgbox("Cell A1s in " & ws1.name & " and " & ws2.name  & " are the same.")
Else
     msgbox("Cell A1s in " & ws1.name & " and " & ws2.name  & " are Not the same.")
end if
 

Watch MrExcel Video

Forum statistics

Threads
1,122,162
Messages
5,594,615
Members
413,917
Latest member
devansh02

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
Top