Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Using VBA to sort a column of data

Hi Forum,

I would be very grateful if anyone could offer any help with regards to
using VBA to automate the following task;

I have a column (A) of numerical data in ascending order that changes in
size from day to day (which is why recording a macro is not best suited). I
would like to use code to automate the way the data could be displayed in
columns moving left to right 6 rows deep whilst maintaining its ascendancy.
The following is a simplified example;

A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 and so on..

Ideally would become;

A B C D E

1 7 13
2 8 14
3 9 15
4 10 16
5 11 17
6 12 18

As always any help would be greatly appreciated
Many Thanks
Matt

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Using VBA to sort a column of data

Matt
What you describe is called Snaking a column.
Try this macro and see if it works for you. I assumed your initial data
is in Column A starting in row 1. If your data starts in some other row,
find the line that says "c=1" and change the "1" to your starting row
number.. Post back if you need more. HTH Otto
Sub ReFormat()
Dim iTarget As Long
Dim c As Long
iTarget = 1
c = 1
Application.ScreenUpdating = False
Do
Cells(c, 1).Resize(6).Cut Destination:=Cells(1, iTarget)
c = c + 6
iTarget = iTarget + 1
Loop Until IsEmpty(Cells(c, 1).Value)
Application.ScreenUpdating = True
End Sub

"matt3542" wrote in message
...
Hi Forum,

I would be very grateful if anyone could offer any help with regards to
using VBA to automate the following task;

I have a column (A) of numerical data in ascending order that changes in
size from day to day (which is why recording a macro is not best suited).
I
would like to use code to automate the way the data could be displayed in
columns moving left to right 6 rows deep whilst maintaining its
ascendancy.
The following is a simplified example;

A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 and so on..

Ideally would become;

A B C D E

1 7 13
2 8 14
3 9 15
4 10 16
5 11 17
6 12 18

As always any help would be greatly appreciated
Many Thanks
Matt


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Using VBA to sort a column of data

Hi Otto, apologies for the delay replying, many thanks for taking the time to
offer a solution to my problem. I have just tried the code and it works
beautifully!

Best Regards
Matt

"Otto Moehrbach" wrote:

Matt
What you describe is called Snaking a column.
Try this macro and see if it works for you. I assumed your initial data
is in Column A starting in row 1. If your data starts in some other row,
find the line that says "c=1" and change the "1" to your starting row
number.. Post back if you need more. HTH Otto
Sub ReFormat()
Dim iTarget As Long
Dim c As Long
iTarget = 1
c = 1
Application.ScreenUpdating = False
Do
Cells(c, 1).Resize(6).Cut Destination:=Cells(1, iTarget)
c = c + 6
iTarget = iTarget + 1
Loop Until IsEmpty(Cells(c, 1).Value)
Application.ScreenUpdating = True
End Sub

"matt3542" wrote in message
...
Hi Forum,

I would be very grateful if anyone could offer any help with regards to
using VBA to automate the following task;

I have a column (A) of numerical data in ascending order that changes in
size from day to day (which is why recording a macro is not best suited).
I
would like to use code to automate the way the data could be displayed in
columns moving left to right 6 rows deep whilst maintaining its
ascendancy.
The following is a simplified example;

A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 and so on..

Ideally would become;

A B C D E

1 7 13
2 8 14
3 9 15
4 10 16
5 11 17
6 12 18

As always any help would be greatly appreciated
Many Thanks
Matt



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
2 columns have same data:Sort column E, but column A changes as we MUTTMIND Excel Worksheet Functions 1 February 16th 09 11:27 AM
How do I sort data in column B to align with data in column A? Jephri1 New Users to Excel 1 April 18th 08 05:05 AM
data, sort option is grayed. how to sort on a column? Steve Richter Excel Discussion (Misc queries) 1 September 25th 07 03:25 PM
I want to convert word column data to excel row data to sort addre craywill Excel Discussion (Misc queries) 0 April 18th 06 07:16 PM
How do I sort a column of data and have each data row sort accordi Oedalis Excel Discussion (Misc queries) 1 March 17th 05 11:52 PM


All times are GMT +1. The time now is 09:42 AM.

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"