|
-
Mar 7th, 2006, 10:32 PM
#1
Re: Can this be done? (Excel Macro Probably Needed)
Wouldn't be hard at all. It's hard to tell from your post, but are the A### entries in cells across the row, or is the whole line in one cell?
-
Mar 8th, 2006, 08:24 AM
#2
Thread Starter
Fanatic Member
Re: Can this be done? (Excel Macro Probably Needed)
Sorry, yes...each entry has it's own column and is in it's own cell.
So column A would be "name" and then B,C,D,E etc may have codes, up to a maximum of probably 10.
Last edited by The_Grudge; Mar 8th, 2006 at 08:29 AM.
-
Mar 8th, 2006, 09:00 AM
#3
Re: Can this be done? (Excel Macro Probably Needed)
Try this:
VB Code:
Private Sub SplitRows()
Dim oRange As Range, lRow As Long, lCol As Long, oOut As Worksheet, lOut As Long
Dim sValue As String, sName As String
Set oRange = Application.ActiveSheet.UsedRange 'Get the range of used cells.
Set oOut = Application.ActiveWorkbook.Worksheets.Add 'Create an output worksheet.
For lRow = 1 To oRange.Rows.Count 'Loop through all rows.
sName = oRange.Cells(lRow, 1).Value 'Get the name from column A.
sName = Trim$(sName) 'Trim it.
If Len(sName) <> 0 Then 'Check to see if there is an entry.
For lCol = 2 To oRange.Columns.Count 'Loop through the remaining columns.
sValue = oRange.Cells(lRow, lCol).Value 'Get the value from that cell.
sValue = Trim$(sValue) 'Trim it.
If Len(sValue) <> 0 Then 'See if there is a value there.
lOut = lOut + 1 'Increment the output row counter.
oOut.Cells(lOut, 1).Value = sName 'Write the name cell.
oOut.Cells(lOut, 2).Value = sValue 'Write the value cell.
End If
Next lCol
End If
Next lRow
Set oRange = Nothing 'Release objects.
Set oOut = Nothing
End Sub
-
Mar 8th, 2006, 10:02 AM
#4
Thread Starter
Fanatic Member
Re: Can this be done? (Excel Macro Probably Needed)
That works really well with a little tweak here and there (cell range) so thanks!
I just have one more question. If I have more columns across the top how do I copy them over as well.
So (commas indicate columns)
JOE SMITH, A303, A505, N858, 788 Beverly Hills Ave, Los Angeles
Should Read....
JOE SMITH, A303, 788 Beverly Hills Ave, Los Angeles
JOE SMITH, A505, 788 Beverly Hills Ave, Los Angeles
JOE SMITH, N858, 788 Beverly Hills Ave, Los Angeles
You follow? 
Oh, the counter doesn't seem to print on the new page either...but I think I can tweak it.
-
Mar 8th, 2006, 10:50 AM
#5
Thread Starter
Fanatic Member
Re: Can this be done? (Excel Macro Probably Needed)
Nevermind, I got it.
Thanks man, you saved my mouse hand A LOT of dickin' around LOL
-
Mar 8th, 2006, 10:50 AM
#6
Re: Can this be done? (Excel Macro Probably Needed)
Just copy them out at the same time the name is copied. It looks like they will be in a fixed column or always in the last column. If it's fixed, it's really easy, just always write that cell the same place in the code that the name writes. If it's always in the last cell (but not always in the same column), it's a little trickier. You might scan all of the cell values into an array, and then use first element / last element in each row, and then loop through the middle of the array.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|