VBA Function

I

IPerlovsky

How to combine 3 macros to run together. First, I would like to unprotect
all sheets for which I am using the following macro:

Sub unprotectAll()
Dim myCount
Dim i
myCount = Application.Sheets.Count
Sheets(1).Select
For i = 1 To myCount
ActiveSheet.Unprotect Password:="1"
If i = myCount Then
End
End If
ActiveSheet.Next.Select
Next i
End Sub

Then, I would like to copy and paste values for the entire sheets 22-26 for
which I am trying to use this macro but getting errors:

Sub CopyRange()
Dim myCount
Dim i
myCount = Application.Sheets.Count
Sheets(22).Select
For i = 22 To myCount
ActiveSheet.Range("A1:IV5000").Paste values Destination:=Range("A1:IV5000")
End Sub

Then, I would like delete sheets 1-21, for which I am not sure about the
routine. Some important things to note are that the sheets are not called
“sheet 1â€, “sheet 2â€, etc, but have specific names. The sequence of the
sheets in the file does not change however, so I believe it would be simpler
to identify them by number, correct? Finally, how to run this as one
routine, rather than 3 separate macros?
 
D

Don Guillett

try this

Sub fixAll()'Notice the . dots
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect passwork:="1"
Next i
End Sub
 
I

IPerlovsky

That function is giving me the following Compile error: Next without For.
Additionally, does this routine do all 3 tasks:
1) unprotect all sheets
2) copy and paste over with values for sheets 22-26
3) delete sheets 1-21
 
D

Don Guillett

forgot the sheets delete part
Sub fixAll()'Notice the . dots
application.displayalerts=false
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect password:="1"
Next i

Sheets([Transpose(Row(1:21))]).delete

application.displayalerts=true
End Sub
 
D

Don Guillett

Sub fixAll()'Notice the . dots
application.displayalerts=false
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect password:="1"
end with
Next i

Sheets([Transpose(Row(1:21))]).delete

application.displayalerts=true
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Don Guillett said:
forgot the sheets delete part
Sub fixAll()'Notice the . dots
application.displayalerts=false
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect password:="1"
Next i

Sheets([Transpose(Row(1:21))]).delete

application.displayalerts=true
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Don Guillett said:
try this

Sub fixAll()'Notice the . dots
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect passwork:="1"
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
 
I

IPerlovsky

thanks that worked without a hitch!
--
iperlovsky


Don Guillett said:
Sub fixAll()'Notice the . dots
application.displayalerts=false
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect password:="1"
end with
Next i

Sheets([Transpose(Row(1:21))]).delete

application.displayalerts=true
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Don Guillett said:
forgot the sheets delete part
Sub fixAll()'Notice the . dots
application.displayalerts=false
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect password:="1"
Next i

Sheets([Transpose(Row(1:21))]).delete

application.displayalerts=true
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Don Guillett said:
try this

Sub fixAll()'Notice the . dots
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect passwork:="1"
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
How to combine 3 macros to run together. First, I would like to
unprotect
all sheets for which I am using the following macro:

Sub unprotectAll()
Dim myCount
Dim i
myCount = Application.Sheets.Count
Sheets(1).Select
For i = 1 To myCount
ActiveSheet.Unprotect Password:="1"
If i = myCount Then
End
End If
ActiveSheet.Next.Select
Next i
End Sub

Then, I would like to copy and paste values for the entire sheets 22-26
for
which I am trying to use this macro but getting errors:

Sub CopyRange()
Dim myCount
Dim i
myCount = Application.Sheets.Count
Sheets(22).Select
For i = 22 To myCount
ActiveSheet.Range("A1:IV5000").Paste values
Destination:=Range("A1:IV5000")
End Sub

Then, I would like delete sheets 1-21, for which I am not sure about the
routine. Some important things to note are that the sheets are not
called
“sheet 1â€, “sheet 2â€, etc, but have specific names. The sequence of the
sheets in the file does not change however, so I believe it would be
simpler
to identify them by number, correct? Finally, how to run this as one
routine, rather than 3 separate macros?
 
D

Don Guillett

I'm glad this old man finally got it together for you.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
IPerlovsky said:
thanks that worked without a hitch!
--
iperlovsky


Don Guillett said:
Sub fixAll()'Notice the . dots
application.displayalerts=false
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect password:="1"
end with
Next i

Sheets([Transpose(Row(1:21))]).delete

application.displayalerts=true
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Don Guillett said:
forgot the sheets delete part
Sub fixAll()'Notice the . dots
application.displayalerts=false
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect password:="1"
Next i

Sheets([Transpose(Row(1:21))]).delete

application.displayalerts=true
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
try this

Sub fixAll()'Notice the . dots
For i = 22 To sheets.count
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect passwork:="1"
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
How to combine 3 macros to run together. First, I would like to
unprotect
all sheets for which I am using the following macro:

Sub unprotectAll()
Dim myCount
Dim i
myCount = Application.Sheets.Count
Sheets(1).Select
For i = 1 To myCount
ActiveSheet.Unprotect Password:="1"
If i = myCount Then
End
End If
ActiveSheet.Next.Select
Next i
End Sub

Then, I would like to copy and paste values for the entire sheets
22-26
for
which I am trying to use this macro but getting errors:

Sub CopyRange()
Dim myCount
Dim i
myCount = Application.Sheets.Count
Sheets(22).Select
For i = 22 To myCount
ActiveSheet.Range("A1:IV5000").Paste values
Destination:=Range("A1:IV5000")
End Sub

Then, I would like delete sheets 1-21, for which I am not sure about
the
routine. Some important things to note are that the sheets are not
called
“sheet 1â€, “sheet 2â€, etc, but have specific names. The sequence of
the
sheets in the file does not change however, so I believe it would be
simpler
to identify them by number, correct? Finally, how to run this as one
routine, rather than 3 separate macros?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top