#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 32
Default VBA Function

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?
--
iperlovsky
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default VBA Function

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

"IPerlovsky" wrote in message
...
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?
--
iperlovsky


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 32
Default VBA Function

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

--
iperlovsky


"Don Guillett" wrote:

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

"IPerlovsky" wrote in message
...
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?
--
iperlovsky



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default VBA Function


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

"Don Guillett" wrote in message
...
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

"IPerlovsky" wrote in message
...
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?
--
iperlovsky



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default VBA Function


I forgot the end with
with sheets(i)
.Unprotect Password:="1"
.UsedRange.value =.usedrange.value
.protect passwork:="1"

END WITH
Next i


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"IPerlovsky" wrote in message
...
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

--
iperlovsky


"Don Guillett" wrote:

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

"IPerlovsky" wrote in message
...
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?
--
iperlovsky






  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default VBA Function

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

"Don Guillett" wrote in message
...

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

"Don Guillett" wrote in message
...
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

"IPerlovsky" wrote in message
...
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?
--
iperlovsky




  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 32
Default VBA Function

thanks that worked without a hitch!
--
iperlovsky


"Don Guillett" wrote:

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

"Don Guillett" wrote in message
...

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

"Don Guillett" wrote in message
...
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

"IPerlovsky" wrote in message
...
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?
--
iperlovsky




  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default VBA Function

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"IPerlovsky" wrote in message
...
thanks that worked without a hitch!
--
iperlovsky


"Don Guillett" wrote:

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

"Don Guillett" wrote in message
...

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

"Don Guillett" wrote in message
...
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

"IPerlovsky" wrote in message
...
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?
--
iperlovsky





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM
Nested IF Function, Date Comparing, and NetworkDays Function carl Excel Worksheet Functions 2 December 29th 04 09:57 PM


All times are GMT +1. The time now is 07:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"