Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copy & paste ranges dependant on results from another calculation

I am trying to set up asheet which will dynamically copy & paste formatted
cells a number of times. However this process will change depending on the
results of a separate calculation;

So far I can calculate the number of iterations and display the result in a
cell, I now need to select the range of cells to be copied e.g. range
("A1:C5") and copy this range 'n' times adjacent to my originating block.

If I look at the code from a recorded macro the code reads as follows:
--
range("A1:C5").Select
Selection.Copy
range("D1").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
range("G1").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

How can I refer to my calculated result in order to set the macro to
automatically PasteSpecial 'n' number of times?
--
Cheers,

Andy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Copy & paste ranges dependant on results from another calculation

Try this.

Sub Test()
Dim n%, i%

'Assuming the number of times the pasting is to be done is in Cell A6
n = Cells(6, 1).Value

If n 84 Then n = 84

Range("A1:C5").Select
Selection.Copy

For i = 1 To n
Cells(1, 1 + i * 3).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Next i

End Sub


"AndyOD" wrote:

I am trying to set up asheet which will dynamically copy & paste formatted
cells a number of times. However this process will change depending on the
results of a separate calculation;

So far I can calculate the number of iterations and display the result in a
cell, I now need to select the range of cells to be copied e.g. range
("A1:C5") and copy this range 'n' times adjacent to my originating block.

If I look at the code from a recorded macro the code reads as follows:
--
range("A1:C5").Select
Selection.Copy
range("D1").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
range("G1").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

How can I refer to my calculated result in order to set the macro to
automatically PasteSpecial 'n' number of times?
--
Cheers,

Andy

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copy & paste ranges dependant on results from another calculat

Alok,

Thank you for this. It is exactly what I was looking for. Brilliant!
--
Cheers,

Andy


"Alok" wrote:

Try this.

Sub Test()
Dim n%, i%

'Assuming the number of times the pasting is to be done is in Cell A6
n = Cells(6, 1).Value

If n 84 Then n = 84

Range("A1:C5").Select
Selection.Copy

For i = 1 To n
Cells(1, 1 + i * 3).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Next i

End Sub


"AndyOD" wrote:

I am trying to set up asheet which will dynamically copy & paste formatted
cells a number of times. However this process will change depending on the
results of a separate calculation;

So far I can calculate the number of iterations and display the result in a
cell, I now need to select the range of cells to be copied e.g. range
("A1:C5") and copy this range 'n' times adjacent to my originating block.

If I look at the code from a recorded macro the code reads as follows:
--
range("A1:C5").Select
Selection.Copy
range("D1").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
range("G1").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

How can I refer to my calculated result in order to set the macro to
automatically PasteSpecial 'n' number of times?
--
Cheers,

Andy

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Copy & paste ranges dependant on results from another calculation

Andy,

Try this:

Sub paste_n_times()
Dim copy_range As Range
Dim n As Long

Set copy_range = Range("A1:C5")
n = 3 'replace with your calc

With copy_range
.Copy
With .Resize(.Rows.Count, .Columns.Count * (n + 1))
.PasteSpecial Paste:=xlPasteFormulas
.PasteSpecial Paste:=xlPasteFormats
End With
End With
End Sub


hth,

Doug


"AndyOD" wrote in message
...
I am trying to set up asheet which will dynamically copy & paste formatted
cells a number of times. However this process will change depending on the
results of a separate calculation;

So far I can calculate the number of iterations and display the result in
a
cell, I now need to select the range of cells to be copied e.g. range
("A1:C5") and copy this range 'n' times adjacent to my originating block.

If I look at the code from a recorded macro the code reads as follows:
--
range("A1:C5").Select
Selection.Copy
range("D1").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
range("G1").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

How can I refer to my calculated result in order to set the macro to
automatically PasteSpecial 'n' number of times?
--
Cheers,

Andy



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
How can I copy big ranges of cells without drag or copy/paste? Ricardo Julio Excel Discussion (Misc queries) 3 March 23rd 10 02:38 PM
using macro to copy and paste filtered results, what if blank? priceyindevon Excel Worksheet Functions 2 December 14th 06 10:09 AM
copy and paste cells to a different worksheet according to IF results faze Excel Programming 1 February 1st 06 02:41 PM
Copy paste ranges from multiple sheets Woody1313 Excel Programming 2 January 30th 06 03:37 PM
Copy and Paste ranges between files dude Excel Programming 3 July 23rd 03 01:37 PM


All times are GMT +1. The time now is 07:56 PM.

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

About Us

"It's about Microsoft Excel"