Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Copy & paste block of text number of times equal to value in cell

I have a block of text ranging from B5 to H28 that needs to be copied and
pasted below each other. The number of times it needs to be copied is
specified by the user of the worksheet in cell G4. I can get the block to
copy and paste once, but I don't know how to link it to the value in G4.
Thanks in advance for any suggestions!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,836
Default Copy & paste block of text number of times equal to value in cell

There may be a couple of ways to do what you want (I hope this is what you
want):

#1)
Sub CopyVariableRows()
Dim i As Long
Dim j As Long
Dim LastRow As Long
Dim cell As Range
Dim numval As Long
Dim Z As Long
Dim ws As Worksheet
Z = 1

Set ws = Worksheets("Copy Variable Rows")
LastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In ws.Range("A1:A" & LastRow)
For i = 1 To Len(cell.Value)
numval = Mid(cell.Value, i, 1)
For j = 1 To numval
ws.Cells(Z, "B").Value = numval
Z = Z + 1
Next
Next
Next
End Sub

#2)
Sub CopyVariableRows2()
Dim X As Long
Dim Z As Long
Dim Index As Long
Dim LastRow As Long
Dim Total As Long
Dim Contents() As Long
With Worksheets("Copy Variable Rows")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Total = Application.WorksheetFunction.Sum(.Range("A1:A" & LastRow))
If Total Rows.Count Then
MsgBox "Error - You will go past the end of the worksheet!"
Exit Sub
End If
ReDim Contents(1 To Total)
For X = 1 To LastRow
For Z = 1 To .Cells(X, "A").Value
Index = Index + 1
Contents(Index) = .Cells(X, "A").Value
Next
Next
For X = 1 To Total
..Cells(X, "A").Value = Contents(X)
Next
End With
End Sub


HTH,
Ryan---


--
RyGuy


"azoll" wrote:

I have a block of text ranging from B5 to H28 that needs to be copied and
pasted below each other. The number of times it needs to be copied is
specified by the user of the worksheet in cell G4. I can get the block to
copy and paste once, but I don't know how to link it to the value in G4.
Thanks in advance for any suggestions!

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 to make text in a cell equal a number Dantron Excel Discussion (Misc queries) 6 April 4th 23 10:09 AM
Macro - copy a range and paste it in a new sheet 12 times Eva Excel Worksheet Functions 0 September 26th 07 07:20 PM
want to copy entire text box and paste in new cell delbridk Excel Discussion (Misc queries) 4 October 2nd 06 05:33 PM
Copy Text from cell to paste on New Web Query vovlov Excel Discussion (Misc queries) 0 May 19th 06 01:21 PM
Extract phone number front block of text Tech Excel Discussion (Misc queries) 6 August 8th 05 04:07 PM


All times are GMT +1. The time now is 11:41 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"