View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dana Dana is offline
external usenet poster
 
Posts: 45
Default Individual record spans multiple rows

Ignore that last post. I entered your code into VB editor in excel, and it
seemed to work, EXCEPT that it just pulled all of the charges up to the very
first name's row instead of seeing the next name and pulling that name's
charges up onto that row. Any suggestions?

"JLatham" wrote:

I suspect there are many names to be dealt with, and that they may not all
have same number of charges.

I'm thinking this code could help. Change the two Const values as needed
and test it on a copy of your workbook. It assumes that things are laid out
as in the example and not much else on the sheets.

Sub TransposeChargeData()
Const nameColumn = "A" ' change as needed
Const startRow = 2 ' row w/1st name in it
Dim lastNameRow As Long
Dim nameRow As Long
Dim rOffset As Long
Dim cOffset As Long
Dim baseCell As Range

If Val(Left(Application.Version, 2)) < 12 Then
'pre-2007 Excel
lastNameRow = Range(nameColumn & Rows.Count).End(xlUp).Row
Else
'Excel 2007 or later
lastNameRow = Range(nameColumn & Rows.CountLarge).End(xlUp).Row
End If
Set baseCell = Range(nameColumn & startRow)
Do Until rOffset lastNameRow
If IsEmpty(baseCell.Offset(rOffset + 1, 0)) _
And Not (IsEmpty(baseCell.Offset(rOffset, 0))) Then
cOffset = 1 ' initialize/reset
Do Until IsEmpty(baseCell.Offset(rOffset + cOffset, 1))
baseCell.Offset(rOffset, cOffset + 1).Value = _
baseCell.Offset(rOffset + cOffset, 1).Value
baseCell.Offset(rOffset + cOffset, 1) = "" ' remove entry
cOffset = cOffset + 1 ' look for next charge
Loop
End If
rOffset = rOffset + 1 ' look for next name
Loop
End Sub


"Dana" wrote:

I have a huge excel file from a company that I am trying to print statements
from. There are hundreds of records for individuals that are formatted
something like this:

Name Charges
John Doe First Charge
Second Charge
Third Charge

How can I reformat these records so that they appear like this:

Name Charge1 Charge 2 Charge 3
John Doe First Charge Second Charge Third Charge

Any suggestions would be greatly appreciated. Thank You.