I am new to VBA. I am currently creating a form for my thesis study. But I bumped to a "Subscript out of range" Error 9. It also don't show "Debug" option in the notification. All is working before I enter that code.
Can anyone help me to solve or redo this? Here is the code:
Sub show_Sale_Available_Data()
Dim dsh As Worksheet
Dim sh As Worksheet
Set dsh = ThisWorkbook.Sheets("Sale_Available")
Set sh = ThisWorkbook.Sheets("Sale_Availabale_Display")
dsh.AutoFilterMode = False
dsh.Range("H:H").NumberFormat = "D-MMM-YYYY"
'''' filter here
dsh.UsedRange.AutoFilter 8, ">=" & Me.txt_Date_start.Value, xlAnd, "<=" & Me.txt_Date_End.Value
If Me.OptionButton2.Value = True Then
dsh.UsedRange.AutoFilter 3, "Add to Stocks"
End If
If Me.OptionButton7.Value = True Then
dsh.UsedRange.AutoFilter 3, "Sale"
End If
sh.UsedRange.Clear
dsh.UsedRange.Copy
sh.Range("A1").PasteSpecial xlpastevalueandnumberformats
''' show data in listbox
Dim lr As Long
lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))
If lr = 1 Then lr = 2
With Me.ListBox2
.ColumnCount = 8
.ColumnHeads = True
.ColumnWidths = "0,150,65,65,65,65,65,65"
.RowSource = sh.Name & "!A2:H" & lr
End With
End Sub