PC Review


Reply
Thread Tools Rate Thread

How do I split one table in multiple tables base on condition?

 
 
SNK
Guest
Posts: n/a
 
      27th Mar 2008
I have set of data in two columns. This data should get segregated in
different tables which will further be used for plotting graphs (depending on
the number of tables the data is segregated/ sorted in. The data is like
this: 1-2, 2-3, 3-4, 4-5, 4-6,6-7. Here note that the first number is in one
column and second in another. data in other columnns is associated with set
of these ftwo columns. If u observe the data, the chain breaks at node 4
where there is branching from 4 to 5 and 4 to 6. in another branch the chain
continues from 6-7. Now I need to end one chain from 1---4-5 and another
chain from 1----4-6-7. This should be generated in two (as number of branches
are 2) tables. Two graphs will be generated based on these two tables. pl.
suggest a macro for this.
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      27th Mar 2008
The way to do this is to copy each range of data to a new worksheet. Add a
column to the Master worksheet indicating which rows were copied. Also sort
the data by the first number to simplify the coding. continue looping
through the code until all rows ae copied.

I did not test the code below, but it basically does the job. the code will
work with multiple ranges of data, not just two groups. I used the first
column as the first number and the second column as the 2nd number. these
are respectively B and C after I inserted a new column.




Sub split_table()

'add column to use as marker to indicate which rows were used
With Sheets("Master")
.Columns("A:A").Insert
'sort by first column of table now 2nd column
.Rows("1:16").Sort _
Key1:=.Range("B1"), _
Order1:=xlAscending, _
Header:=xlGuess
Do
RowCount = 1
First = True
Do While .Range("B" & RowCount) <> ""
'check if row was used
If .Range("A" & RowCount) = "" Then
If First = True Then
'create new worksheet
Sheets.Add after:=Sheets(Sheets.Count)
Set NewSheet = ActiveSheet
NewRowCount = 1
FindNum = .Range("C" & RowCount)
First = False
.Range("A" & RowCount) = "Copied"
.Rows(RowCount).Copy _
Destination:=NewSheet.Rows(NewRowCount)
NewRowCount = NewRowCount + 1
Else
If .Range("B" & RowCount) = FindNum Then
.Range("A" & RowCount) = "Copied"
.Rows(RowCount).Copy _
Destination:=NewSheet.Rows(NewRowCount)
NewRowCount = NewRowCount + 1
FindNum = .Range("C" & RowCount)
End If
End If
End If
RowCount = RowCount + 1
Loop
Loop While First = False
End With
End Sub


"SNK" wrote:

> I have set of data in two columns. This data should get segregated in
> different tables which will further be used for plotting graphs (depending on
> the number of tables the data is segregated/ sorted in. The data is like
> this: 1-2, 2-3, 3-4, 4-5, 4-6,6-7. Here note that the first number is in one
> column and second in another. data in other columnns is associated with set
> of these ftwo columns. If u observe the data, the chain breaks at node 4
> where there is branching from 4 to 5 and 4 to 6. in another branch the chain
> continues from 6-7. Now I need to end one chain from 1---4-5 and another
> chain from 1----4-6-7. This should be generated in two (as number of branches
> are 2) tables. Two graphs will be generated based on these two tables. pl.
> suggest a macro for this.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to split one table into 2 tables thru a form Steve in MN Microsoft Access Form Coding 2 17th Nov 2008 07:21 PM
Split Table to multiple tables Jürgen Germonpré Microsoft Access Queries 11 1st Aug 2007 06:55 PM
How do I split one large table into multiple tables based on field value? jimpaige Microsoft Access Queries 6 7th Jun 2007 01:03 AM
Update multiple base tables. Sezgin Rafed Microsoft ADO .NET 1 16th Dec 2004 04:58 AM
re-linking tables in a split data base CD Tom Microsoft Access Forms 1 14th Jan 2004 03:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:49 PM.