Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default reorder information

I have info in a spreadsheet that outlines the hours per week that a person
spends on a particular job. eg.


NAME JOB 18/6/07 25/6/07 2/7/07
Joe Bloggs ROAD 40 40 40
Charlie Brown ROAD 20 20 0
Susie Q ROAD 0 0 40
Charlie Brown BRIDGE 20 20 40
Susie Q BRIDGE 40 40 0

I would like to view this info in a different way but am not sure how to go
about it. I would like a list of names, each name appearing once and under
the date heading would appear the job that they worked on. Therefore the info
above would look like this:

NAME 18/6/07 25/6/07 2/7/07
Joe Bloggs ROAD ROAD ROAD
Charlie Brown ROAD, BRIDGE ROAD, BRIDGE BRIDGE
Susie Q BRIDGE BRIDGE ROAD

I don't want to use another sheet with formulas as it would be really heavy.
I thought running a macro would work but don't know how to do it.

Any help would be appreciated.

Ellen
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default reorder information

The following puts your desired data below the existing data. Adapt if
you want it elsewhere.

Hth,
Merjet

Sub Macro1()
Dim c1 As Range
Dim c2 As Range
Dim iRow1 As Long
Dim iRow2 As Long
Dim iRow3 As Long

iRow1 = Range("A1").End(xlDown).Row
iRow2 = iRow1 + 2
Range("A1:A" & iRow1).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("A" & iRow2), Unique:=True
Range("C1:E1").Copy Range("C" & iRow2)
iRow3 = Range("A65536").End(xlUp).Row
For Each c2 In Range("A" & iRow2 + 1 & ":A" & iRow3)
For Each c1 In Range("A2:A" & iRow1)
If c1 = c2 Then
For iCol = 3 To 5
If c1.Offset(0, iCol - 1) 0 Then c2.Offset(0, iCol -
1) _
= c2.Offset(0, iCol - 1) & c1.Offset(0, 1) & ",
"
Next iCol
End If
Next c1
Next c2
For Each c2 In Range("C" & iRow2 + 1 & ":E" & iRow3)
c2 = Left(c2, Len(c2) - 2) 'clean up -- remove last ", "
Next c2
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default reorder information



"merjet" wrote:

The following puts your desired data below the existing data. Adapt if
you want it elsewhere.

Hth,
Merjet

Sub Macro1()
Dim c1 As Range
Dim c2 As Range
Dim iRow1 As Long
Dim iRow2 As Long
Dim iRow3 As Long

iRow1 = Range("A1").End(xlDown).Row
iRow2 = iRow1 + 2
Range("A1:A" & iRow1).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("A" & iRow2), Unique:=True
Range("C1:E1").Copy Range("C" & iRow2)
iRow3 = Range("A65536").End(xlUp).Row
For Each c2 In Range("A" & iRow2 + 1 & ":A" & iRow3)
For Each c1 In Range("A2:A" & iRow1)
If c1 = c2 Then
For iCol = 3 To 5
If c1.Offset(0, iCol - 1) 0 Then c2.Offset(0, iCol -
1) _
= c2.Offset(0, iCol - 1) & c1.Offset(0, 1) & ",
"
Next iCol
End If
Next c1
Next c2
For Each c2 In Range("C" & iRow2 + 1 & ":E" & iRow3)
c2 = Left(c2, Len(c2) - 2) 'clean up -- remove last ", "
Next c2
End Sub




Thanks, but I get an error at this line

If c1.Offset(0, iCol - 1) 0 Then c2.Offset(0, iCol -
1) _
= c2.Offset(0, iCol - 1) & c1.Offset(0, 1) & ",
"

do you know why?

e
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default reorder information

What kind of error? If the lines are red in the VBE it's because long
lines can get broken when posted here. The following should be only
two lines in the VBE. (In another sense, it's only one line, given the
line continuation symbol.)


If c1.Offset(0, iCol - 1) 0 Then c2.Offset(0, iCol - 1) _
= c2.Offset(0, iCol - 1) & c1.Offset(0, 1) & ","

Hth,
Merjet

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default reorder information

I am getting runtime error 400. Nothing is red.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default reorder information

What kind of error? If the lines are red in the VBE it's because long
lines can get broken when posted here. The following should be only
two lines in the VBE. (In another sense, it's only one line, given the
line continuation symbol.)


If c1.Offset(0, iCol - 1) 0 Then c2.Offset(0, iCol - 1) _
= c2.Offset(0, iCol - 1) & c1.Offset(0, 1) & ","

Hth,
Merjet



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default reorder information

hi, i am getting runtime error 400. there are no red lines. do you know what
could be worng? could i send you my spreadsheet?

e

"merjet" wrote:

What kind of error? If the lines are red in the VBE it's because long
lines can get broken when posted here. The following should be only
two lines in the VBE. (In another sense, it's only one line, given the
line continuation symbol.)


If c1.Offset(0, iCol - 1) 0 Then c2.Offset(0, iCol - 1) _
= c2.Offset(0, iCol - 1) & c1.Offset(0, 1) & ","

Hth,
Merjet




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default reorder information

runtime error 400. do you know how to fix it? would it be possible to send
you my spreadsheet?

e

"merjet" wrote:

What kind of error? If the lines are red in the VBE it's because long
lines can get broken when posted here. The following should be only
two lines in the VBE. (In another sense, it's only one line, given the
line continuation symbol.)


If c1.Offset(0, iCol - 1) 0 Then c2.Offset(0, iCol - 1) _
= c2.Offset(0, iCol - 1) & c1.Offset(0, 1) & ","

Hth,
Merjet




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
Reorder String msnyc07 Excel Worksheet Functions 0 February 16th 10 10:49 PM
reorder data ellebelle Excel Worksheet Functions 0 June 19th 07 10:00 AM
Reorder columns? Arinté Excel Discussion (Misc queries) 0 October 24th 06 06:33 PM
reorder function cb chiam Excel Worksheet Functions 0 August 2nd 05 11:28 PM
VB function to reorder names? Will Tyson Excel Programming 4 May 23rd 04 12:53 AM


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