ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error in vba module (https://www.excelbanter.com/excel-programming/392833-error-vba-module.html)

ADK

Error in vba module
 
The first code group works. The second group does not. I get an error:

Run-time error '-2147417848 (80010108)':
Method 'Hidden' of object 'Range' failed

Any ideas on fixing this?

-Using Excel 2000
-Code is placed in Module1
-Original code worked for 2 sheets, when adding 3 sheets, it fails.

Original code:

Sub AddRowNowMacro()
ActiveSheet.Unprotect ("atsi359j")
Dim lHiddenRws As Long
With Cells.SpecialCells(xlCellTypeVisible)
lHiddenRws = .Areas(1).Rows.Count + 1
.Areas(1)(lHiddenRws, 1).EntireRow.Hidden = False
Range("A1").CurrentRegion.Rows(Range("A1") _
.CurrentRegion.Rows.Count).Copy Destination:= _
Range("A1").CurrentRegion.Rows(Range("A1").Current Region.Rows.Count + 1)
End With
ActiveSheet.Protect ("atsi359j")
Sheets("CompletionTable").Select
ActiveSheet.Unprotect ("atsi359j")
Dim lHiddenRwsb As Long
With Cells.SpecialCells(xlCellTypeVisible)
lHiddenRwsb = .Areas(1).Rows.Count + 1
.Areas(1)(lHiddenRwsb, 1).EntireRow.Hidden = False
Range("A1").CurrentRegion.Rows(Range("A1") _
.CurrentRegion.Rows.Count).Copy Destination:= _
Range("A1").CurrentRegion.Rows(Range("A1").Current Region.Rows.Count + 1)
End With
ActiveSheet.Protect ("atsi359j")
Sheets("PDSR").Select
End Sub

--------------------------------------------------------------------
Updated code:

Sub AddRowNowMacro()
ActiveSheet.Unprotect ("password")
Dim lHiddenRws As Long
With Cells.SpecialCells(xlCellTypeVisible)
lHiddenRws = .Areas(1).Rows.Count + 1
.Areas(1)(lHiddenRws, 1).EntireRow.Hidden = False
Range("A1").CurrentRegion.Rows(Range("A1") _
.CurrentRegion.Rows.Count).Copy Destination:= _
Range("A1").CurrentRegion.Rows(Range("A1").Current Region.Rows.Count + 1)
End With
ActiveSheet.Protect ("password")
Sheets("CompletionTable").Select
ActiveSheet.Unprotect ("password")
Dim lHiddenRwsb As Long
With Cells.SpecialCells(xlCellTypeVisible)
lHiddenRwsb = .Areas(1).Rows.Count + 1
.Areas(1)(lHiddenRwsb, 1).EntireRow.Hidden = False
Range("A1").CurrentRegion.Rows(Range("A1") _
.CurrentRegion.Rows.Count).Copy Destination:= _
Range("A1").CurrentRegion.Rows(Range("A1").Current Region.Rows.Count + 1)
End With
ActiveSheet.Protect ("password")
Sheets("Disciplines").Select
ActiveSheet.Unprotect ("password")
Dim lHiddenRwsc As Long
With Cells.SpecialCells(xlCellTypeVisible)
lHiddenRwsc = .Areas(1).Rows.Count + 1
.Areas(1)(lHiddenRwsc, 1).EntireRow.Hidden = False
Range("A1").CurrentRegion.Rows(Range("A1") _
.CurrentRegion.Rows.Count).Copy Destination:= _
Range("A1").CurrentRegion.Rows(Range("A1").Current Region.Rows.Count + 1)
End With
ActiveSheet.Protect ("password")
Sheets("PDSR").Select
End Sub



Dan R.

Error in vba module
 
What are they supposed to do?

--
Dan



All times are GMT +1. The time now is 09:55 AM.

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