Need Assistance Creating Macro Spreadsheet

ams7685

New Member
Joined
Apr 5, 2016
Messages
2
Currently, I have a spreadsheet with 4 checkboxes and a button on the Main page that can be used to compile a list of items based off what you check mark. I'm not very good with creating macros and used a another macroenabled workbook as a guide to creating this one. I have a few questions...

Check Boxes
- I have inserted 4 checkboxes into the Main Page of my workbook. I also have a button at the bottom. Presumably, I would like to let used check what is applicable then click the button to run the macro based off selections. They (checkboxes) are defined in VBA as:

Private Sub TwentyTwelve_Click()
applyFilters
End Sub
Private Sub TwentyFifteen_Click()
applyFilters
End Sub
Private Sub TwentySixteen_Click()
applyFilters
End Sub
Private Sub TwentySeventeen_Click()
applyFilters
End Sub

Question: How do I prevent the macro from running until I click the button I added on the page? Also, should these buttons refer to a specific sheet of data or should it reference a master list with all of the data. I added in a VLookUp to set filters.


Whenever I do click a checkbox on the main page, I receive an error in VBA. "Run-time error '1004': AutoFilter method of range class failed." I'm not sure what is wrong with the bolded line.

Private Sub applyFilters()
Sheets("Master Package List").Select

Range("G:G").EntireColumn.Hidden = False
'Selection.EntireColumn.Hidden
ActiveSheet.Range("$A$2:G$2000").AutoFilter Field:=7, Criteria1:="TRUE"
Range("G:G").EntireColumn.Hidden = True

Sheets("Main Page").Select
Application.ScreenUpdating = True
End Sub



I'm thinking I should just start fresh and not rely on another workbook to coach me through this process... but at that rate I might just quit while ahead. Here is my entire VBA code if you are curious.

Private Sub TwentyTwelve_Click()
applyFilters
End Sub
Private Sub TwentyFifteen_Click()
applyFilters
End Sub
Private Sub TwentySixteen_Click()
applyFilters
End Sub
Private Sub TwentySeventeen_Click()
applyFilters
End Sub
Private Sub PackageGeneration_Click()
Dim row As Integer
Dim curPreRow As Integer
Dim curCutRow As Integer
Application.ScreenUpdating = False
Worksheets("Master Package List").Select

curSelRow = 3

'Unhide tabs
Worksheets("Macro Packages").Visible = True


'Go through each row
Worksheets("Master Package List").Range("F1").Select ActiveCell.Offset(1, 0).Select
While Selection.Value <> ""
If Selection.Value = "2012.01+" Then
Selection.EntireRow.Copy
Worksheets("Macro Packages").Range("A2:F2").Select
ActiveSheet.Paste
If Selection.Value = "2015.01+" Then
Selection.EntireRow.Copy
Worksheets("Macro Packages").Range("A2:F2").Select
ActiveSheet.Paste
If Selection.Value = "2016.01" Then
Selection.EntireRow.Copy
Worksheets("Macro Packages").Range("A2:F2").Select
ActiveSheet.Paste
If Selection.Value = "2017.01" Then
Selection.EntireRow.Copy
Worksheets("Macro Packages").Range("A2:F2").Select
ActiveSheet.Paste
End If
End If
Worksheets("Master Package List").Select
ActiveCell.Offset(1, 0).Select
Wend

'Hide tabs
Worksheets("Main Page").Visible = False
Worksheets("Master Package List").Visible = False
Application.ScreenUpdating = True
End Sub


Private Sub applyFilters()
Sheets("Master Package List").Select

Range("G:G").EntireColumn.Hidden = False
'Selection.EntireColumn.Hidden
ActiveSheet.Range("$A$2:G$2000").AutoFilter Field:=7, Criteria1:="TRUE"
Range("G:G").EntireColumn.Hidden = True

Sheets("Main Page").Select
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I would like to let users**** check what is applicable then click the button to run the macro based off selections.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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