Project/library userform macro error!

jpar1983

New Member
Joined
Aug 11, 2012
Messages
25
Not sure what title to put on this, because the macro I was using was working just fine, until all of a sudden it wasn't. Go figure. Basically I have a workbook with several pages of spreadsheets. The first page is titled "Reporting", the rest are titled by Month and Year ("August 2013"). I also have a userform to do some reporting on these months. The form is two list boxes, one with a list of available worksheets minus the Reporting sheet, the other with a list of potential filter criteria. The intent is to select a sheet, then use the second listbox to filter that sheet by the selected criteria. Worked fine, until all of a sudden it didn't. Now I get "Compile Error: Can't find project or library". When I debug it highlights the first "N" on the first line of code "For N = 0..." Can anyone tell me what is wrong here? Note that I use a lot of 's to take notes on my code so I know what everything does.

Code:
Private Sub CommandButton1_Click()
''''''''''''sheet select
'gets listbox2 item count
For N = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(N) = True Then
'msgbox to confirm selected item, error checking
MsgBox (ListBox2.List(N))
Sheets(ListBox2.List(N)).Select
 
''''''''''''filter criteria
'gets listbox1 item count
For i = 0 To ListBox1.ListCount - 1
'selects filter range
    Range("A3:M3").Select
    Range(Selection, Selection.End(xlDown)).Select
'if/then to find only selected items in listbox 1
If ListBox1.Selected(i) = True Then
'msgbox to confirm selected item, error checking
MsgBox (ListBox1.List(i))
    

'apply autofilter, use current selected item as criteria
Selection.autofilter Field:=5, Criteria1:=Array(ListBox1.List(i))
    
'copy/paste, then turn off autofilter
    Sheets(ListBox2.List(N)).Select
    
    Range("A4:M5000").Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    
    Sheets("Reporting").Select
    Range("A6").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    ActiveSheet.Paste
'for some reason code does not work if I leave autofilter turned on!
    Sheets(ListBox2.List(N)).Select
    Selection.autofilter
'end for next (i) loop
End If
'move on to next item in listbox, or next sheet if at end
Next i
'end for next (n) loop
End If
'move on to next sheet, or return to reports tab if at end
Next N

Sheets("Reporting").Select
Range("A8").Select
    
     Unload Me
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Have a look under Tools>References...

Is there anything listed as MISSING?
 
Upvote 0
MISSING: Microsoft Windows Common Controls-2 6.0 (SP4)

I did just have to replace my computer due to a virus, but I thought it was updated. It is a work computer so I am hesitant to do any more updating without an OK from IT.
 
Upvote 0
What happens if you uncheck that reference?
 
Upvote 0

Forum statistics

Threads
1,215,329
Messages
6,124,302
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