Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Repeat values in a list x number of times

On sheet 1 I have numbers in A2 to A50, (about 50 or 55 maybe 60 numbers.)

1230
1001
2354
.....
.....
etc.

On sheet 2 I want to repeat each number 7 times in A2 to A356 (or there about).
Seven of each value on sheet 2 for as many rows as it takes.

The numbers are unique, but would be helpful to know if it will work if there are some duplicates, or what problems to look out for if there are duplicates.

To solve for unique values only is first priority.

Thanks,
Howard




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Repeat values in a list x number of times

Hi Howard,

Am Fri, 19 Feb 2016 16:16:58 -0800 (PST) schrieb L. Howard:

On sheet 1 I have numbers in A2 to A50, (about 50 or 55 maybe 60 numbers.)

1230
1001
2354
....
....
etc.

On sheet 2 I want to repeat each number 7 times in A2 to A356 (or there about).
Seven of each value on sheet 2 for as many rows as it takes.

The numbers are unique, but would be helpful to know if it will work if there are some duplicates, or what problems to look out for if there are duplicates.

To solve for unique values only is first priority.


try:

Sub Test()
Dim LRow As Long, i As Long, n As Long
Dim varData As Variant, varTmp As Variant
Dim myDic As Object

With Sheets("Sheet1")
LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
varData = .Range("A2:A" & LRow)
'unique values
Set myDic = CreateObject("Scripting.Dictionary")
For i = LBound(varData) To UBound(varData)
myDic(varData(i, 1)) = varData(i, 1)
Next
varTmp = myDic.items
End With

n = 2
For i = LBound(varTmp) To UBound(varTmp)
Sheets("Sheet2").Cells(n, 1).Resize(7) = varTmp(i)
n = n + 7
Next
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Repeat values in a list x number of times


To solve for unique values only is first priority.


try:

Sub Test()
Dim LRow As Long, i As Long, n As Long
Dim varData As Variant, varTmp As Variant
Dim myDic As Object

With Sheets("Sheet1")
LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
varData = .Range("A2:A" & LRow)
'unique values
Set myDic = CreateObject("Scripting.Dictionary")
For i = LBound(varData) To UBound(varData)
myDic(varData(i, 1)) = varData(i, 1)
Next
varTmp = myDic.items
End With

n = 2
For i = LBound(varTmp) To UBound(varTmp)
Sheets("Sheet2").Cells(n, 1).Resize(7) = varTmp(i)
n = n + 7
Next
End Sub


Regards
Claus B.
--



You're the Boss! Perfect.

Thanks, Claus.

Howard
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
repeat number multiple times Brenda from Michigan Excel Discussion (Misc queries) 4 May 7th 09 01:17 PM
repeat list 5 times hab Excel Discussion (Misc queries) 5 April 24th 09 09:37 PM
LIST OF THE NUMBERS, AND HOW MANY TIMES THEY REPEAT? dperalta Excel Worksheet Functions 3 July 18th 08 06:25 PM
Repeat statements "x" number of times... Frantic Excel-er Excel Discussion (Misc queries) 14 July 1st 05 04:19 PM
how do I get a calculation to repeat various number of times? weelittlekim Excel Worksheet Functions 1 October 27th 04 08:13 PM


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