Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default VBA to create new data help please

I have 4 different sets of datalists currently.

Dataset A, with values A1, A2, A3,....
Dataset B, with values B1, B2, B3,.....
Dataset C, with values C1, C2, C3,.....
Dataset D, with values D1, D2, D3,.....

What I need to do is 'merge' them all together to create a 4 column list
with each possible combination.

i.e.

A1,B1,C1,D1
A1,B2,C1,D2....
A1,B1,C2,D1
A1,B1,C2,D2.... etc

I may not have explained this very well and am not that good with VBA so any
help at all, appreciated please. Happy to try and explain further!
Many thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default VBA to create new data help please

does this code:

Sub kombin()
Dim counter as Integer

For j =1 to Range("A1:A3").Cells.Count
For k =1 to Range("B1:B3").Cells.Count
For m =1 to Range("C1:C3").Cells.Count
For n =1 to Range("D1:D3").Cells.Count

counter = counter + 1

Cells(Counter+6,1)=Cells(1,j)
Cells(Counter+6,2)=Cells(1,k)
Cells(Counter+6,3)=Cells(1,m)
Cells(Counter+6,4)=Cells(1,n)


Next n
Next m
Next k
Next j

End Sub

do what you're up to?

adjust your ranges to suit


On 9 Kwi, 11:08, Andy wrote:
I have 4 different sets of datalists currently.

Dataset A, with values A1, A2, A3,....
Dataset B, with values B1, B2, B3,.....
Dataset C, with values C1, C2, C3,.....
Dataset D, with values D1, D2, D3,.....

What I need to do is 'merge' them all together to create a 4 column list
with each possible combination.

i.e.

A1,B1,C1,D1
A1,B2,C1,D2....
A1,B1,C2,D1
A1,B1,C2,D2.... etc

I may not have explained this very well and am not that good with VBA so any
help at all, appreciated please. Happy to try and explain further!
Many thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default VBA to create new data help please

Hello Andy,

This is the program that combines a1,a2,a3 with b1,b2 amd b3 and c1,c2,c3
with d1,d2 and d3:


------------------------------------------------------------------

Sub kombin()
Dim counter As Integer
Range("a7:d87").Clear
For j = 1 To 3
For k = 1 To 3
For m = 1 To 3
For n = 1 To 3

counter = counter + 1
Cells(counter + 6, 1) = Cells(j, 1)
Cells(counter + 6, 2) = Cells(k, 2)
Cells(counter + 6, 3) = Cells(m, 3)
Cells(counter + 6, 4) = Cells(n, 4)
Next n
Next m

Next k
Next j
End Sub
-----------------------------------------------------------
My a1-a3 was 1,11,111
b1-b3 was 2,22,222
c1-c3 was 3,33,333
d1-d3 was 4,44,444
----------------------------------------------------------------
the output is:

1 2 3 4
1 2 3 44
1 2 3 444
1 2 33 4
1 2 33 44
1 2 33 444
1 2 333 4
1 2 333 44
1 2 333 444
1 22 3 4
1 22 3 44
1 22 3 444
1 22 33 4
1 22 33 44
1 22 33 444
1 22 333 4
1 22 333 44
1 22 333 444
1 222 3 4
1 222 3 44
1 222 3 444
1 222 33 4
1 222 33 44
1 222 33 444
1 222 333 4
1 222 333 44
1 222 333 444
11 2 3 4
11 2 3 44
11 2 3 444
11 2 33 4
11 2 33 44
11 2 33 444
11 2 333 4
11 2 333 44
11 2 333 444
11 22 3 4
11 22 3 44
11 22 3 444
11 22 33 4
11 22 33 44
11 22 33 444
11 22 333 4
11 22 333 44
11 22 333 444
11 222 3 4
11 222 3 44
11 222 3 444
11 222 33 4
11 222 33 44
11 222 33 444
11 222 333 4
11 222 333 44
11 222 333 444
111 2 3 4
111 2 3 44
111 2 3 444
111 2 33 4
111 2 33 44
111 2 33 444
111 2 333 4
111 2 333 44
111 2 333 444
111 22 3 4
111 22 3 44
111 22 3 444
111 22 33 4
111 22 33 44
111 22 33 444
111 22 333 4
111 22 333 44
111 22 333 444
111 222 3 4
111 222 3 44
111 222 3 444
111 222 33 4
111 222 33 44
111 222 33 444
111 222 333 4
111 222 333 44
111 222 333 444


----- Original Message -----
From: "Andy"
Newsgroups: microsoft.public.excel.programming
Sent: Friday, April 09, 2010 5:08 AM
Subject: VBA to create new data help please



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
Create chart using part of data table (data legend) Koulla Charts and Charting in Excel 0 October 21st 09 08:17 AM
Create WB, create new Sht, paste data. (Macro not working) Rick S. Excel Programming 6 October 31st 07 05:33 PM
Use detailed data in one worksheet to create summary data as chart source rdemyan Charts and Charting in Excel 0 January 23rd 07 02:18 PM
create Macro €“ select data, sort by acc no., yr, part no, create P Johnny Excel Programming 0 November 22nd 06 03:18 PM
create macro to move label type data to column data JonathonWood9 Excel Programming 4 February 21st 05 10:53 PM


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