Macros Across Worksheets

DazHands

New Member
Joined
Jun 2, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi I am trying to create a form where different a different subject may be chosen and depending on which one, certain questions need to be asked but this is required across two separate “forms” which I have set up as “worksheet”. However, I can only seem to hide the rows I don’t want on both sheets by running two separate Macros – is there a way to just run one Macro but which hides the rows across both sheets>

What I have at present is:

Workbook “Initial Assessment” – where Cell E1 changes depending on the subject.

Sub HideRowCellNumValue()
StartRow = 81
LastRow = 556
iCol = 1
For i = StartRow To LastRow
If Cells(i, iCol).Value = Range("G1").Value Then
Cells(i, iCol).EntireRow.Hidden = False
Else
Cells(i, iCol).EntireRow.Hidden = True
End If
Next i
End Sub


When run, this Macro hides any row between 81 – 556 where Column 1 (column A on the Sheet) does not contain the name of the subject in Cell E1

I have a second sheet in this workbook (Tab4 - Plan of Training) which I want to link to the subject in “E1” on the Initial Assessment sheet and likewise hide certain rows depending on the subject (rows 81 – 556).

However the only way I have managed it is to run a separate Macro (sort of replicating the first but changed for the applicable rows)

Sub HideRowCellNumValue()
StartRow = 81
LastRow = 556
iCol = 1
For i = StartRow To LastRow
If Cells(i, iCol).Value = Range("G1").Value Then
Cells(i, iCol).EntireRow.Hidden = False
Else
Cells(i, iCol).EntireRow.Hidden = True
End If
Next i
End Sub


Is there a way to hide the applicable rows in the second sheet based on the selection in the first with only one macro needed to be run?

Thanks
 
The routine is not that complicated so I suspect that whatever issues there are, are minor. For example you said that the name of the 2nd worksheet was "Tab4 - Plan of Training", but if it was actually just "Plan of Training" then the code would never execute. But since you have not posted any testable data it is not possible to tell. If you are not willing/able to do some minimal debugging then yes, you are better off sticking with what you have that works. Cheers.
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,215,326
Messages
6,124,260
Members
449,149
Latest member
mwdbActuary

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