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

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.
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,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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