Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default vba code to sort data?

Hi All,

I am an absolute newbie to excel and vba. All I want to do is copy
data which is in the following format :

A B
identifier1: Result1
identifier2: Result2
identifier3: Result3
identifier4: Result4
identifier5: Result5



identifier1: Result6
identifier2: Result7
identifier3: Result8
identifier4: Result9
identifier5: Result10

........
.........

into a new worksheet sorted to look like the following;

A B C D E
identifier1 identifier2 identifier3 identifier4
identifier5
Result1 Result2 Result3 Result4 Result5
Result6 Result7 Result8 Result9
Result10

and so on.....

i think whats causing me grief is the space of about 5 rows seperating
each 'sets' of identifiers and results.

currently i have something similar to the following;

Sub selectData()
Dim field As String
If ActiveCell.Text = "" Then
ActiveCell.Offset(0, -1).Activate
Else: ActiveCell.Offset(1, 0).Activate
End If
field = ActiveCell.Value
Worksheets("Output").Activate
End sub

ive concentrated on trying to check whether if the field is blank or
not...Im not too sure where to go next, I keep getting lost!

any ideas? much appreciated...

eadie.

any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default vba code to sort data?

eadie,

Here's some code that will work. Name the sheet with the original data, "1"
and the sheet with the converted data, "2".
Put your "identifier1", "identifier2",... headers in the first five cells of
Row1 on sheet "2".

HTH, Shockley


Sub Tester()
With ThisWorkbook.Sheets("1").Columns(1)
LastRow = .Cells(.Rows.Count).End(xlUp).Row
For i = 1 To LastRow
sID = .Cells(i)
sResult = .Cells(i).Offset(0, 1)
If sID < Empty Then _
EnterData sID, sResult
Next i
End With
End Sub
Sub EnterData(sID, sResult)
With ThisWorkbook.Sheets("2")
iColumn = Val(Left(Right(sID, 2), 1))
LastRow = .Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row
.Cells(LastRow + 1, iColumn) = sResult
End With
End Sub

'Or, a more general solution for the EnterData sub:

Sub EnterData2(sID, sResult)
With ThisWorkbook.Sheets("2")
sID1 = Left(sID, Len(sID) - 1)
iColumn = .Rows(1).Find(sID1).Column
LastRow = .Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row
.Cells(LastRow + 1, iColumn) = sResult
End With
End Sub













"eadie" wrote in message
om...
Hi All,

I am an absolute newbie to excel and vba. All I want to do is copy
data which is in the following format :

A B
identifier1: Result1
identifier2: Result2
identifier3: Result3
identifier4: Result4
identifier5: Result5



identifier1: Result6
identifier2: Result7
identifier3: Result8
identifier4: Result9
identifier5: Result10

.......
........

into a new worksheet sorted to look like the following;

A B C D E
identifier1 identifier2 identifier3 identifier4
identifier5
Result1 Result2 Result3 Result4 Result5
Result6 Result7 Result8 Result9
Result10

and so on.....

i think whats causing me grief is the space of about 5 rows seperating
each 'sets' of identifiers and results.

currently i have something similar to the following;

Sub selectData()
Dim field As String
If ActiveCell.Text = "" Then
ActiveCell.Offset(0, -1).Activate
Else: ActiveCell.Offset(1, 0).Activate
End If
field = ActiveCell.Value
Worksheets("Output").Activate
End sub

ive concentrated on trying to check whether if the field is blank or
not...Im not too sure where to go next, I keep getting lost!

any ideas? much appreciated...

eadie.

any ideas?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default vba code to sort data?

Hi Shockley,

thanks for your help, although i cant seem to get it working
the following line is throwing up an error;

LastRow = .Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row

any ideas?




"shockley" wrote in message ...
eadie,

Here's some code that will work. Name the sheet with the original data, "1"
and the sheet with the converted data, "2".
Put your "identifier1", "identifier2",... headers in the first five cells of
Row1 on sheet "2".

HTH, Shockley


Sub Tester()
With ThisWorkbook.Sheets("1").Columns(1)
LastRow = .Cells(.Rows.Count).End(xlUp).Row
For i = 1 To LastRow
sID = .Cells(i)
sResult = .Cells(i).Offset(0, 1)
If sID < Empty Then _
EnterData sID, sResult
Next i
End With
End Sub
Sub EnterData(sID, sResult)
With ThisWorkbook.Sheets("2")
iColumn = Val(Left(Right(sID, 2), 1))
LastRow = .Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row
.Cells(LastRow + 1, iColumn) = sResult
End With
End Sub

'Or, a more general solution for the EnterData sub:

Sub EnterData2(sID, sResult)
With ThisWorkbook.Sheets("2")
sID1 = Left(sID, Len(sID) - 1)
iColumn = .Rows(1).Find(sID1).Column
LastRow = .Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row
.Cells(LastRow + 1, iColumn) = sResult
End With
End Sub













"eadie" wrote in message
om...
Hi All,

I am an absolute newbie to excel and vba. All I want to do is copy
data which is in the following format :

A B
identifier1: Result1
identifier2: Result2
identifier3: Result3
identifier4: Result4
identifier5: Result5



identifier1: Result6
identifier2: Result7
identifier3: Result8
identifier4: Result9
identifier5: Result10

.......
........

into a new worksheet sorted to look like the following;

A B C D E
identifier1 identifier2 identifier3 identifier4
identifier5
Result1 Result2 Result3 Result4 Result5
Result6 Result7 Result8 Result9
Result10

and so on.....

i think whats causing me grief is the space of about 5 rows seperating
each 'sets' of identifiers and results.

currently i have something similar to the following;

Sub selectData()
Dim field As String
If ActiveCell.Text = "" Then
ActiveCell.Offset(0, -1).Activate
Else: ActiveCell.Offset(1, 0).Activate
End If
field = ActiveCell.Value
Worksheets("Output").Activate
End sub

ive concentrated on trying to check whether if the field is blank or
not...Im not too sure where to go next, I keep getting lost!

any ideas? much appreciated...

eadie.

any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default vba code to sort data?

eadie,

What's the error you're getting? My guess: "subscript out of range"? If so,
you need to make sure your worksheets are named exactly as I have them in
the macro.

With ThisWorkbook.Sheets("1").Columns(1)

is not the same as

With ThisWorkbook.Sheets(1).Columns(1)

The sheet tabs on the two worksheets should show "1" and "2" without the
quotes.

Regards,
Shockley




"eadie" wrote in message
m...
Hi Shockley,

thanks for your help, although i cant seem to get it working
the following line is throwing up an error;

LastRow = .Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row

any ideas?




"shockley" wrote in message

...
eadie,

Here's some code that will work. Name the sheet with the original data,

"1"
and the sheet with the converted data, "2".
Put your "identifier1", "identifier2",... headers in the first five

cells of
Row1 on sheet "2".

HTH, Shockley


Sub Tester()
With ThisWorkbook.Sheets("1").Columns(1)
LastRow = .Cells(.Rows.Count).End(xlUp).Row
For i = 1 To LastRow
sID = .Cells(i)
sResult = .Cells(i).Offset(0, 1)
If sID < Empty Then _
EnterData sID, sResult
Next i
End With
End Sub
Sub EnterData(sID, sResult)
With ThisWorkbook.Sheets("2")
iColumn = Val(Left(Right(sID, 2), 1))
LastRow = .Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row
.Cells(LastRow + 1, iColumn) = sResult
End With
End Sub

'Or, a more general solution for the EnterData sub:

Sub EnterData2(sID, sResult)
With ThisWorkbook.Sheets("2")
sID1 = Left(sID, Len(sID) - 1)
iColumn = .Rows(1).Find(sID1).Column
LastRow = .Cells(.Cells.Rows.Count, iColumn).End(xlUp).Row
.Cells(LastRow + 1, iColumn) = sResult
End With
End Sub













"eadie" wrote in message
om...
Hi All,

I am an absolute newbie to excel and vba. All I want to do is copy
data which is in the following format :

A B
identifier1: Result1
identifier2: Result2
identifier3: Result3
identifier4: Result4
identifier5: Result5



identifier1: Result6
identifier2: Result7
identifier3: Result8
identifier4: Result9
identifier5: Result10

.......
........

into a new worksheet sorted to look like the following;

A B C D E
identifier1 identifier2 identifier3 identifier4
identifier5
Result1 Result2 Result3 Result4 Result5
Result6 Result7 Result8 Result9
Result10

and so on.....

i think whats causing me grief is the space of about 5 rows seperating
each 'sets' of identifiers and results.

currently i have something similar to the following;

Sub selectData()
Dim field As String
If ActiveCell.Text = "" Then
ActiveCell.Offset(0, -1).Activate
Else: ActiveCell.Offset(1, 0).Activate
End If
field = ActiveCell.Value
Worksheets("Output").Activate
End sub

ive concentrated on trying to check whether if the field is blank or
not...Im not too sure where to go next, I keep getting lost!

any ideas? much appreciated...

eadie.

any ideas?



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
sort by zip code daniel Excel Discussion (Misc queries) 2 March 17th 09 11:05 PM
Sort by how many addresses per zip code Susienak Excel Discussion (Misc queries) 4 August 1st 08 06:32 PM
sort by code Jay Excel Discussion (Misc queries) 1 February 11th 08 01:09 PM
Sort Macro: Help with code. Tail Wind Excel Discussion (Misc queries) 13 September 2nd 07 07:46 PM
Sort Code Modification Todd Huttenstine\(Remote\) Excel Programming 1 November 27th 03 08:18 AM


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