ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   getting Run-time error '1004' Select Method of Worksheet Classfailed (https://www.excelbanter.com/excel-programming/430500-getting-run-time-error-1004-select-method-worksheet-classfailed.html)

mitesh

getting Run-time error '1004' Select Method of Worksheet Classfailed
 
Hello,

I've created excel sheet contains macros and connected with SQL query.
I am getting error mentioned in subject line.

Note: After recording the macro i've hide worksheet through VBA code
with password. Before hiding worksheet macros was run fine but after
hiding the worksheet it shows me above error.

I am getting error on line " sheets("Sheet2"). Select.

Sheet2 which is hidden by VBA code after macros was recorded.

Below is whole query:

Sub Finaloutput()
'
' Finaloutput Macro
'
' Keyboard Shortcut: Ctrl+a
'
Sheets("Sheet2").Select
Cells.Select
Selection.Copy
Sheets("Sheet6").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array
(1, 2, 3, 4, _
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), Replace:=True,
PageBreaks:=False, _
SummaryBelowData:=True
Selection.Copy
Sheets("Sheet8").Select
Range("J13").Select
ActiveWindow.SmallScroll Down:=-15
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Columns("A:A").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
Range("C8").Select
Cells.Replace What:=" Total", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,
_
ReplaceFormat:=False
Cells.Select
Selection.Copy
Sheets("Sheet7").Select
ActiveWindow.SmallScroll Down:=-24
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("K11").Select
Sheets("Sheet5").Select
Range("A7").Select
Sheets("Sheet4").Select
Range("AE5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet5").Select
Range("A7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("A7").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Sheet5").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet5").Sort.SortField s.Add Key:=Range
("A7"), _
SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet5").Sort
.SetRange Range("A7:N162")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("G10").Select
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlNotEqual, _
Formula1:="=0"
Selection.FormatConditions
(Selection.FormatConditions.Count).SetFirstPriorit y
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("J15").Select
End Sub






All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com