RUN DIFFERENT MACROS ACCORDING TO CELL VALUE IN A RANGE

MONIM10

New Member
Joined
Nov 14, 2022
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
I need to run macro from a group of macros according to cell value within range of cells when a cell value in other range of cells changed
For more details:
I have 8 macros named "group1", "group2", … , "group8"
I have range of cells (B5:B52) the cell value in the range maybe 1 or 2 or 3 or , … , 8 these cells values will not be changed
I have range of cells (G5:H52) will be changed according to user input
Examples:
If cell G5 or H5 changed and cell B5 value is 1 then run macro "group1" (Note that: changeable cell in columns B, G and H with same row number are in relation)
If cell G9 or H9 changed and cell B9 value is 5 then run macro "group5" (Note that: changeable cell in columns B, G and H with same row number are in relation)

Regards
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Welcome to the forum,
You can put this code inthe worksheet code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim id As Integer
If Not Intersect(Target, Range("G5:H52")) Is Nothing Then
rowno = Target.Row
id = Cells(rowno, 2)
Select Case (id)
Case 1
Call Group1
Case 2
Call Group2
Case 3
Call Group3
Case 4
Call Group4
Case 5
Call Group5
Case 6
Call Group6
Case 7
Call Group7
Case 8
Call Group8
End Select
End If
End Sub
 
Upvote 0
Solution
Welcome to the forum,
You can put this code inthe worksheet code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim id As Integer
If Not Intersect(Target, Range("G5:H52")) Is Nothing Then
rowno = Target.Row
id = Cells(rowno, 2)
Select Case (id)
Case 1
Call Group1
Case 2
Call Group2
Case 3
Call Group3
Case 4
Call Group4
Case 5
Call Group5
Case 6
Call Group6
Case 7
Call Group7
Case 8
Call Group8
End Select
End If
End Sub
Do you mean by case 1,2, ... , 8 the cell value in range B5:B52?
 
Upvote 0
My code automatically detects which row of G or H has been changed and then pick up the value from column B as input to the case statement
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,572
Members
453,054
Latest member
arz007

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