#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Loop - Tabs

Hi, I am in need of some help.
I want to copy and paste from one worksheet to 31 tabs. I have got as far as
getting a loop to change the data on the main page (below) but what I need
now is to incorporate into the code so that the main page changes data,
copies to sheet 1(They are named as people) goes back to main page,
recalculates for next persons data, copy then paste into the next worksheet
along and so on until it has populated all sheets (31 of them)

Sub Copy_Paste()
Dim num As Long
For num = 1 To 32
With ActiveSheet
Application.Wait Now + TimeValue("00:00:01") 'This is to allow the
spreadsheet time to calculate
Range("X2").Value = .Range("X2").Value + 1 'Formula works off this
cell
.Range("X4").Value = num
.Calculate
End With

Next num
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Loop - Tabs

Assumes the first sheet is the Main sheet
Sub Copy_Paste()
Dim num As Long
For num = 1 To 31
With Worksheets(1)
.Range("X2").Value = .Range("X2").Value + 1
.Range("X4").Value = num
.Calculate
doevents
.cells.copy
End with
worksheets(num +1).PasteSpecial xlValues
Next num
End Sub

Calculate isn't asynchronous, so unless you are having problems, you
shouldn't have to "wait". The code will "wait" automaticaly.

--
Regards,
Tom Ogilvy

"JohnUK" wrote:

Hi, I am in need of some help.
I want to copy and paste from one worksheet to 31 tabs. I have got as far as
getting a loop to change the data on the main page (below) but what I need
now is to incorporate into the code so that the main page changes data,
copies to sheet 1(They are named as people) goes back to main page,
recalculates for next persons data, copy then paste into the next worksheet
along and so on until it has populated all sheets (31 of them)

Sub Copy_Paste()
Dim num As Long
For num = 1 To 32
With ActiveSheet
Application.Wait Now + TimeValue("00:00:01") 'This is to allow the
spreadsheet time to calculate
Range("X2").Value = .Range("X2").Value + 1 'Formula works off this
cell
.Range("X4").Value = num
.Calculate
End With

Next num
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Loop - Tabs

Hi Tom,
Thank you again for your help.
I have tried to run the code but it stops on the:
Worksheets(num + 1).PasteSpecial xlValues

"Tom Ogilvy" wrote:

Assumes the first sheet is the Main sheet
Sub Copy_Paste()
Dim num As Long
For num = 1 To 31
With Worksheets(1)
.Range("X2").Value = .Range("X2").Value + 1
.Range("X4").Value = num
.Calculate
doevents
.cells.copy
End with
worksheets(num +1).PasteSpecial xlValues
Next num
End Sub

Calculate isn't asynchronous, so unless you are having problems, you
shouldn't have to "wait". The code will "wait" automaticaly.

--
Regards,
Tom Ogilvy

"JohnUK" wrote:

Hi, I am in need of some help.
I want to copy and paste from one worksheet to 31 tabs. I have got as far as
getting a loop to change the data on the main page (below) but what I need
now is to incorporate into the code so that the main page changes data,
copies to sheet 1(They are named as people) goes back to main page,
recalculates for next persons data, copy then paste into the next worksheet
along and so on until it has populated all sheets (31 of them)

Sub Copy_Paste()
Dim num As Long
For num = 1 To 32
With ActiveSheet
Application.Wait Now + TimeValue("00:00:01") 'This is to allow the
spreadsheet time to calculate
Range("X2").Value = .Range("X2").Value + 1 'Formula works off this
cell
.Range("X4").Value = num
.Calculate
End With

Next num
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Loop - Tabs

i think. that line just needs a range to copy to.
for example:
Worksheets(num + 1).Range("A1").PasteSpecial xlValues

see how it goes after changing it.
--


Gary


"JohnUK" wrote in message
...
Hi Tom,
Thank you again for your help.
I have tried to run the code but it stops on the:
Worksheets(num + 1).PasteSpecial xlValues

"Tom Ogilvy" wrote:

Assumes the first sheet is the Main sheet
Sub Copy_Paste()
Dim num As Long
For num = 1 To 31
With Worksheets(1)
.Range("X2").Value = .Range("X2").Value + 1
.Range("X4").Value = num
.Calculate
doevents
.cells.copy
End with
worksheets(num +1).PasteSpecial xlValues
Next num
End Sub

Calculate isn't asynchronous, so unless you are having problems, you
shouldn't have to "wait". The code will "wait" automaticaly.

--
Regards,
Tom Ogilvy

"JohnUK" wrote:

Hi, I am in need of some help.
I want to copy and paste from one worksheet to 31 tabs. I have got as far
as
getting a loop to change the data on the main page (below) but what I need
now is to incorporate into the code so that the main page changes data,
copies to sheet 1(They are named as people) goes back to main page,
recalculates for next persons data, copy then paste into the next worksheet
along and so on until it has populated all sheets (31 of them)

Sub Copy_Paste()
Dim num As Long
For num = 1 To 32
With ActiveSheet
Application.Wait Now + TimeValue("00:00:01") 'This is to allow the
spreadsheet time to calculate
Range("X2").Value = .Range("X2").Value + 1 'Formula works off this
cell
.Range("X4").Value = num
.Calculate
End With

Next num
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Loop - Tabs

Superb
Many thanks I really appriciate the help


"Gary Keramidas" wrote:

i think. that line just needs a range to copy to.
for example:
Worksheets(num + 1).Range("A1").PasteSpecial xlValues

see how it goes after changing it.
--


Gary


"JohnUK" wrote in message
...
Hi Tom,
Thank you again for your help.
I have tried to run the code but it stops on the:
Worksheets(num + 1).PasteSpecial xlValues

"Tom Ogilvy" wrote:

Assumes the first sheet is the Main sheet
Sub Copy_Paste()
Dim num As Long
For num = 1 To 31
With Worksheets(1)
.Range("X2").Value = .Range("X2").Value + 1
.Range("X4").Value = num
.Calculate
doevents
.cells.copy
End with
worksheets(num +1).PasteSpecial xlValues
Next num
End Sub

Calculate isn't asynchronous, so unless you are having problems, you
shouldn't have to "wait". The code will "wait" automaticaly.

--
Regards,
Tom Ogilvy

"JohnUK" wrote:

Hi, I am in need of some help.
I want to copy and paste from one worksheet to 31 tabs. I have got as far
as
getting a loop to change the data on the main page (below) but what I need
now is to incorporate into the code so that the main page changes data,
copies to sheet 1(They are named as people) goes back to main page,
recalculates for next persons data, copy then paste into the next worksheet
along and so on until it has populated all sheets (31 of them)

Sub Copy_Paste()
Dim num As Long
For num = 1 To 32
With ActiveSheet
Application.Wait Now + TimeValue("00:00:01") 'This is to allow the
spreadsheet time to calculate
Range("X2").Value = .Range("X2").Value + 1 'Formula works off this
cell
.Range("X4").Value = num
.Calculate
End With

Next num
End Sub






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Loop - Tabs

I had meant it to be:

Sub Copy_Paste()
Dim num As Long
For num = 1 To 31
With Worksheets(1)
.Range("X2").Value = .Range("X2").Value + 1
.Range("X4").Value = num
.Calculate
doevents
.cells.copy
End with
worksheets(num +1).Cells.PasteSpecial xlValues
Next num
End Sub

But adding Range("A1") works as well.

--
Regards,
Tom Ogilvy



"JohnUK" wrote:

Hi Tom,
Thank you again for your help.
I have tried to run the code but it stops on the:
Worksheets(num + 1).PasteSpecial xlValues

"Tom Ogilvy" wrote:

Assumes the first sheet is the Main sheet
Sub Copy_Paste()
Dim num As Long
For num = 1 To 31
With Worksheets(1)
.Range("X2").Value = .Range("X2").Value + 1
.Range("X4").Value = num
.Calculate
doevents
.cells.copy
End with
worksheets(num +1).PasteSpecial xlValues
Next num
End Sub

Calculate isn't asynchronous, so unless you are having problems, you
shouldn't have to "wait". The code will "wait" automaticaly.

--
Regards,
Tom Ogilvy

"JohnUK" wrote:

Hi, I am in need of some help.
I want to copy and paste from one worksheet to 31 tabs. I have got as far as
getting a loop to change the data on the main page (below) but what I need
now is to incorporate into the code so that the main page changes data,
copies to sheet 1(They are named as people) goes back to main page,
recalculates for next persons data, copy then paste into the next worksheet
along and so on until it has populated all sheets (31 of them)

Sub Copy_Paste()
Dim num As Long
For num = 1 To 32
With ActiveSheet
Application.Wait Now + TimeValue("00:00:01") 'This is to allow the
spreadsheet time to calculate
Range("X2").Value = .Range("X2").Value + 1 'Formula works off this
cell
.Range("X4").Value = num
.Calculate
End With

Next num
End Sub

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
tabs are missing even though 'tools-options-view-sheet tabs' ok? rgranell Excel Worksheet Functions 3 August 16th 08 04:25 PM
hide tabs from view then lock tabs? slowboat Excel Discussion (Misc queries) 1 December 19th 07 07:06 AM
loop through tabs Newbie Excel Programming 4 January 7th 07 03:33 PM
Run out of resources .... loop to new tabs Doug929 Excel Programming 3 September 16th 05 04:52 PM
Loop to new tabs Doug929 Excel Programming 1 September 15th 05 06:36 PM


All times are GMT +1. The time now is 03:43 PM.

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"