Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Re-structuring data


Hi,

Have 2 columns with 250 rows. Each value in A has a B value.
There are 15 different B values.
I need to write a Macro which will create another worksheet,
headings for each B value will all the associated A values underneath.
Below is a sample, many thanks


How do I get from

A B
1 a
2 b
3 a
4 a
5 b
6 b
7 a
8 a
9 c
10 c
.........
.....

TO:
a
1
3
4
7
8

b
2
5
6


c
9
10


--
T De Villiers
------------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...o&userid=26479
View this thread: http://www.excelforum.com/showthread...hreadid=530842

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Re-structuring data

Hi,
This assumes data is sorted by column B then A with a header row.

Sub a()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim lastrow As Long, r As Long

Set ws1 = Worksheets("sheet1")
Set ws2 = Worksheets("sheet2")
' assumes data sorted by column B then column A
With ws1
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
r = 2 '<===assumes there is header row
rr = 2
Do
n = Application.CountIf(Range("B:B"), .Cells(r, "B"))
.Cells(r, "B").Copy ws2.Cells(rr, "A")
.Cells(r, "A").Resize(n, 1).Copy ws2.Cells(rr + 1, "A")
r = r + n
rr = rr + n + 2
Loop Until r lastrow
End With
End Sub


HTH
"T De Villiers" wrote:


Hi,

Have 2 columns with 250 rows. Each value in A has a B value.
There are 15 different B values.
I need to write a Macro which will create another worksheet,
headings for each B value will all the associated A values underneath.
Below is a sample, many thanks


How do I get from

A B
1 a
2 b
3 a
4 a
5 b
6 b
7 a
8 a
9 c
10 c
.........
.....

TO:
a
1
3
4
7
8

b
2
5
6


c
9
10


--
T De Villiers
------------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...o&userid=26479
View this thread: http://www.excelforum.com/showthread...hreadid=530842


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Re-structuring data

Hi T

Try this:

Sub SortMe()
Dim sourcesht As Worksheet
Dim destsht As Worksheet
Dim destcell As Range
Dim rw As Integer
Dim val As Byte
Dim test As String
Set sourcesht = ActiveSheet
Worksheets.Add after:=Sheets(Sheets.Count)
Set destsht = ActiveSheet
Set destcell = destsht.Range("A1")

For val = 97 To 111
test = Chr(val)
destcell = test
Set destcell = destcell.Offset(1, 0)
For rw = 1 To 250
If sourcesht.Cells(rw, 2).Value = test Then

destcell = sourcesht.Cells(rw, 1).Value
Set destcell = destcell.Offset(1, 0)
End If
Next
Set destcell = destcell.Offset(1, 0)
Next
End Sub

Regards

Steve

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
Difficulty in structuring regression analysis Luckydog Excel Discussion (Misc queries) 1 July 21st 08 09:22 AM
Increase Your Business By Data Conversion, Data Format and Data EntryServices in India Data Entry India Excel Worksheet Functions 1 March 31st 08 12:51 PM
Save 20% On Data Conversion and Data Formats Services by Data EntryIndia Data Entry India Excel Discussion (Misc queries) 0 March 31st 08 12:00 PM
Data Entry Online, Data Format, Data Conversion and Data EntryServices through Data Entry Outsourcing [email protected] Excel Discussion (Misc queries) 0 March 20th 08 12:45 PM
MULTIPLE DATA - How to insert new data into existing data.... Rodorodo Excel Discussion (Misc queries) 0 December 15th 06 11:50 PM


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