VBA Macro - naming ws1 - "Billed"

tanyaleblanc

Board Regular
Joined
Mar 16, 2019
Messages
145
I'm getting an error "type mismatch" on the ws1 name, not sure why, It worked last month, can someone help me understand.

Sub FinanceOwnedFilter2()
Dim lRow As Long
Dim ws1 As Worksheet, ws2 As Worksheet
Dim i As Long, lastrow As Long
If AutoFilterMode = True And FilterMode = True Then ActiveSheet.ShowAllData
lRow = ActiveSheet.Range("A500").End(xlUp).Row


Set ws1 = "Billed"
Set fd = Application.FileDialog(msoFileDialogFilePicker)


With fd
.AllowMultiSelect = False
.Title = "Please select the file."

' Clear out the current filters, and add our own.
.Filters.Clear
'.Filters.Add "Excel 2003", "*.xls"
'.Filters.Add "All Files", "*.*"

' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
txtfilename = .SelectedItems(1) 'replace txtFileName with your textbox
'MsgBox txtfilename
Workbooks.Open txtfilename
End If
End With
'Debug.Print ActiveWorkbook.Name
Set ws1 = Billed
lRow = ActiveSheet.Range("a500").End(xlUp).Row

With ActiveSheet("Billed")
.AutoFilterMode = False
With Range("a2:m" & lRow)
.AutoFilter
.AutoFilter field:=1, Criteria1:="Payout"

End With
End With
'--------
Dim rang As Range


Set ws2 = Owned
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,
If "Billed" is the name of a worksheet then you need the Worksheets object

Code:
Set ws1 = Worksheets("Billed")


Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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