Select Method of Worksheet Class Failed
Tag : excel , By : Joe Sweeney
Date : March 29 2020, 07:55 AM
wish helps you I don't know what GWP is, but I think you want to use ProjNo there. The Range property doesn't accept an argument like that. Unless you have a named range of "Row,6" which you don't because it's not a legal name, you have to supply Range with a valid range reference, like A6 or D2:D12, for example. Also, you can't concatenate rows and use them in a Range reference to get a larger range. You would have to copy each row inside the loop, union the ranges as you go, or better yet, filter on the value that you want and copy the visible rows. Private Sub btnNext_Click()
With ThisWorkbook.Worksheets("Sheet7")
'filter for the project id
.Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 6).AutoFilter 1, "=" & .Range("D6").Value
'copy the visible rows
.Range("F2", .Cells(.Rows.Count, 6).End(xlUp)).SpecialCells(xlCellTypeVisible).Copy _
ThisWorkbook.Worksheets("Sheet1").Cells(19, 5)
'get rid of the filter
.AutoFilterMode = False
End With
End Sub
|
Excel VBA - ShowAllData method of Worksheet Class failed
Tag : excel , By : alexmajy
Date : March 29 2020, 07:55 AM
should help you out I have automated a proper record input into the table that I use as a database, and when the table is filtered the input don't work. , Here is the working solution I went with : Public Sub UnFilter_DB()
Dim ActiveS As String, CurrScreenUpdate As Boolean
CurrScreenUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
ActiveS = ActiveSheet.Name
Sheets("DB").Activate
Sheets("DB").Range("A1").Activate
On Error Resume Next
If Sheets("DB").FilterMode = True Then Sheets("DB").ShowAllData
On Error GoTo 0
DoEvents
Sheets(ActiveS).Activate
Application.ScreenUpdating = CurrScreenUpdate
End Sub
Private Sub TEST_UnFilter_Table()
Dim tB As Workbook, _
Sh As Worksheet
Set tB = ThisWorkbook
Set Sh = tB.Sheets("DB")
Call UnFilter_Table(Sh, "Db_Val")
End Sub
Public Function UnFilter_Table(ByRef SheetWithTable As Worksheet, ByVal RangeName As String) As Boolean
On Error GoTo ErrHdlr
Dim aWB As Workbook, _
ActiveSH As Worksheet, _
ScreenUpdateState As Boolean, _
StatusBarState As Boolean, _
CalcState As XlCalculation, _
EventsState As Boolean, _
DisplayPageBreakState As Boolean
Set aWB = ActiveWorkbook
Set ActiveSH = aWB.ActiveSheet
DisplayPageBreakState = ActiveSH.DisplayPageBreaks
ActiveSH.DisplayPageBreaks = False
With Application
ScreenUpdateState = .ScreenUpdating
StatusBarState = .DisplayStatusBar
CalcState = .Calculation
EventsState = .EnableEvents
.ScreenUpdating = False
.DisplayStatusBar = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
SheetWithTable.Activate
SheetWithTable.Range(RangeName).Cells(1, 1).Activate
On Error GoTo 0
On Error Resume Next
If SheetWithTable.FilterMode Then SheetWithTable.ShowAllData
On Error GoTo 0
On Error GoTo ErrHdlr
DoEvents
ActiveSH.Activate
ActiveSH.DisplayPageBreaks = DisplayPageBreakState
With Application
.ScreenUpdating = ScreenUpdateState
.DisplayStatusBar = StatusBarState
.Calculation = CalcState
.EnableEvents = EventsState
End With
UnFilter_Table = True
On Error GoTo 0
Exit Function
ErrHdlr:
UnFilter_Table = False
Debug.Print "Error in unfiltering sheet " & SheetWithTable.Name & " !" & vbCrLf & _
"Error n° " & Err.Number & vbCrLf & _
Err.Description
End Function
|
Run-time error '1004' ShowAllData method of Worksheets class failed
Date : November 01 2020, 03:09 PM
like below fixes the issue It depends of the state of FilterMode. Personally, I made this (user won't see anything happening) to cancel filters on a sheet : Public Sub UnFilter_Tables_On_Sheet(Sheet_Name As String)
Dim ActiveS As String, CurrScreenUpdate As Boolean
CurrScreenUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
ActiveS = ActiveSheet.Name
Sheets(Sheet_Name).Activate
Sheets(Sheet_Name).Range("A1").Activate
On Error Resume Next
If Sheets(Sheet_Name).FilterMode = True Then Sheets(Sheet_Name).ShowAllData
On Error GoTo 0
DoEvents
Sheets(ActiveS).Activate
Application.ScreenUpdating = CurrScreenUpdate
End Sub
|
Error 1004 - 'select method of worksheet class failed' when worksheet is Selected
Tag : excel , By : cameron
Date : March 29 2020, 07:55 AM
To fix this issue Name, Index and CodeName are three properties of a worksheet, which are quite different. In the code from the screenshot, Sheet21 is a CodeName and it probably corresponds to Worksheets(17). Worksheet CodeName Property Refer to sheet using codename Sub TestMe()
Dim i As Long
For i = 1 To Worksheets.Count
Debug.Print Worksheets(i).Name
Debug.Print Worksheets(i).Index
Debug.Print Worksheets(i).CodeName
Debug.Print "-----------------------"
Next i
End Sub
|
VBA getting error Active method of Worksheet class failed
Tag : vba , By : user126922
Date : March 29 2020, 07:55 AM
this will help Solution 1: Instead of Sheets.("Discount").Activate write Sheets("Discount").Activate and it should work. E.g., remove the dot.
|