Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 37
Default macro; reorganize blocks of data

I have data on individuals in rows of data. Some patients require just one
row of data from A to AZ. Others require 2 or 3 lines of data always A to AZ.

Each block of data is separated by 1 empty row. There are over 2000 blocks
of data (whether just 1 row, 2 rows, or 3 rows each).

I need a way to reorganize the data. If there is just one row of data, no
change required.
If 2 lines of data, the 2nd line should be arrayed (moved) from the 2nd row
A to AZ to 1st row BA to CZ (next to the first row of data) ie. so all data
is now on one line.

If there are 3 rows of data, the 2nd row would be as above. 3rd row would
also move to 1st row but would go to DA to EZ i.e. all 3 rows of data on 1st
line.

Doesn't matter if there are irregular intervals between lines of data (i.e.
1st rows can stay in same position).

I'll be grateful for any assistance.

Thanks

anand
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 913
Default macro; reorganize blocks of data

On Sat, 12 Apr 2008 20:38:00 -0700, anand
wrote:

I have data on individuals in rows of data. Some patients require just one
row of data from A to AZ. Others require 2 or 3 lines of data always A to AZ.

Each block of data is separated by 1 empty row. There are over 2000 blocks
of data (whether just 1 row, 2 rows, or 3 rows each).

I need a way to reorganize the data. If there is just one row of data, no
change required.
If 2 lines of data, the 2nd line should be arrayed (moved) from the 2nd row
A to AZ to 1st row BA to CZ (next to the first row of data) ie. so all data
is now on one line.

If there are 3 rows of data, the 2nd row would be as above. 3rd row would
also move to 1st row but would go to DA to EZ i.e. all 3 rows of data on 1st
line.

Doesn't matter if there are irregular intervals between lines of data (i.e.
1st rows can stay in same position).

I'll be grateful for any assistance.

Thanks

anand



Try this:

Sub reorg_data(firstrow, lastrow, Optional blockwidth As Integer = 52)
Dim myrow As Integer
Dim mycol As Integer
Dim torow As Integer
Dim deletedrows As Integer
myrow = firstrow
With ActiveSheet
While myrow < lastrow - deletedrows
If .Cells(myrow, 1) < "" Then
mycol = 1
torow = myrow
While Cells(myrow + 1, 1) < ""
mycol = mycol + blockwidth
.Cells(myrow + 1, 1).Resize(1, blockwidth).Select
Selection.Cut
.Cells(torow, mycol).Select
.Paste
.Rows(myrow + 1).EntireRow.Delete shift:=xlUp
deletedrows = deletedrows + 1
Wend
End If
myrow = myrow + 1
Wend
.Cells(firstrow, 1).Select
End With
End Sub

Hope this helps / Lars-Åke
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 37
Default macro; reorganize blocks of data

I get an error when I run the macro.
The error I get when I run the macro is "Argument not optional"
Any ideas?

anand

"Lars-Ã…ke Aspelin" wrote:

On Sat, 12 Apr 2008 20:38:00 -0700, anand
wrote:

I have data on individuals in rows of data. Some patients require just one
row of data from A to AZ. Others require 2 or 3 lines of data always A to AZ.

Each block of data is separated by 1 empty row. There are over 2000 blocks
of data (whether just 1 row, 2 rows, or 3 rows each).

I need a way to reorganize the data. If there is just one row of data, no
change required.
If 2 lines of data, the 2nd line should be arrayed (moved) from the 2nd row
A to AZ to 1st row BA to CZ (next to the first row of data) ie. so all data
is now on one line.

If there are 3 rows of data, the 2nd row would be as above. 3rd row would
also move to 1st row but would go to DA to EZ i.e. all 3 rows of data on 1st
line.

Doesn't matter if there are irregular intervals between lines of data (i.e.
1st rows can stay in same position).

I'll be grateful for any assistance.

Thanks

anand



Try this:

Sub reorg_data(firstrow, lastrow, Optional blockwidth As Integer = 52)
Dim myrow As Integer
Dim mycol As Integer
Dim torow As Integer
Dim deletedrows As Integer
myrow = firstrow
With ActiveSheet
While myrow < lastrow - deletedrows
If .Cells(myrow, 1) < "" Then
mycol = 1
torow = myrow
While Cells(myrow + 1, 1) < ""
mycol = mycol + blockwidth
.Cells(myrow + 1, 1).Resize(1, blockwidth).Select
Selection.Cut
.Cells(torow, mycol).Select
.Paste
.Rows(myrow + 1).EntireRow.Delete shift:=xlUp
deletedrows = deletedrows + 1
Wend
End If
myrow = myrow + 1
Wend
.Cells(firstrow, 1).Select
End With
End Sub

Hope this helps / Lars-Ã…ke

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 913
Default macro; reorganize blocks of data

On Mon, 21 Apr 2008 20:58:00 -0700, anand
wrote:

I get an error when I run the macro.
The error I get when I run the macro is "Argument not optional"
Any ideas?

anand

"Lars-Åke Aspelin" wrote:

On Sat, 12 Apr 2008 20:38:00 -0700, anand
wrote:

I have data on individuals in rows of data. Some patients require just one
row of data from A to AZ. Others require 2 or 3 lines of data always A to AZ.

Each block of data is separated by 1 empty row. There are over 2000 blocks
of data (whether just 1 row, 2 rows, or 3 rows each).

I need a way to reorganize the data. If there is just one row of data, no
change required.
If 2 lines of data, the 2nd line should be arrayed (moved) from the 2nd row
A to AZ to 1st row BA to CZ (next to the first row of data) ie. so all data
is now on one line.

If there are 3 rows of data, the 2nd row would be as above. 3rd row would
also move to 1st row but would go to DA to EZ i.e. all 3 rows of data on 1st
line.

Doesn't matter if there are irregular intervals between lines of data (i.e.
1st rows can stay in same position).

I'll be grateful for any assistance.

Thanks

anand



Try this:

Sub reorg_data(firstrow, lastrow, Optional blockwidth As Integer = 52)
Dim myrow As Integer
Dim mycol As Integer
Dim torow As Integer
Dim deletedrows As Integer
myrow = firstrow
With ActiveSheet
While myrow < lastrow - deletedrows
If .Cells(myrow, 1) < "" Then
mycol = 1
torow = myrow
While Cells(myrow + 1, 1) < ""
mycol = mycol + blockwidth
.Cells(myrow + 1, 1).Resize(1, blockwidth).Select
Selection.Cut
.Cells(torow, mycol).Select
.Paste
.Rows(myrow + 1).EntireRow.Delete shift:=xlUp
deletedrows = deletedrows + 1
Wend
End If
myrow = myrow + 1
Wend
.Cells(firstrow, 1).Select
End With
End Sub

Hope this helps / Lars-Åke


Maybe you forgot to give the two mandatory arguments firstrow and
lastrow when you called the sub reorg_data.

Try this macro to call the macro I suggested:

Sub test()
reorg_data 1,100
End Sub

Change 1 and 100 to the number of the first and last row in your
specific situation.

Hope this helps. / Lars-Åke
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
Count Blocks of Data Brendan Excel Worksheet Functions 4 January 16th 08 10:08 PM
blocks of data repeating eween New Users to Excel 4 March 29th 07 06:58 PM
Reorganize Data JDV Excel Discussion (Misc queries) 4 January 24th 07 12:02 PM
averaging particular blocks of data robert111 Excel Discussion (Misc queries) 6 July 12th 06 02:41 PM
Copy Blocks Of Data SenojNW Excel Discussion (Misc queries) 2 August 9th 05 02:06 AM


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