katkth7533
New Member
- Joined
- Aug 18, 2014
- Messages
- 14
Hi. I have a spreadsheet where I added macros (attached to buttons) that filter information on a long report based on values in 1 column (the information is a department name). There are 7 different macros for the 7 departments. The code I used is
The Department is in the array ("D&C" in this instance. "PN" will appear in all the macros) and I named the Macro "Sub DC_Click()". All the other macros follow the same format with the department name changing. What I want to do is insert the Department name in a cell in the Header of the report based on what macro is running. So if the user selects this macro for "D&C", "D&C" will appear in cell E2 (not the "PN"). How would I do this? The code will need to say something like if Sub DC_Click() is run, insert "D&C"; if Sub Legal_Click() is run, insert "Legal", etc., continuing for all 7 departments. Thank you.
Code:
Sub DC_Click()
Sheets("Tasks").Visible = True
Sheets("Tasks").Range("V5:V6223").AutoFilter Field:=1, Criteria1:=Array("D&C", "PN"), Operator:=xlFilterValues
Sheets("Tasks").Range("B1:I6223").PrintPreview
Sheets("Tasks").Range("V5:V6223").AutoFilter
Sheets("Tasks").Visible = False
End Sub