Converting multiple rows and columns to a single row

JCD1078

New Member
Joined
Aug 27, 2014
Messages
13
I am hoping someone can help me solve this formatting issue I have. I need to be able to take the data I receive in the following format:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]John Smith[/TD]
[TD](111) 111-1111[/TD]
[/TR]
[TR]
[TD]111 Any Road[/TD]
[TD](222) 222-2222[/TD]
[/TR]
[TR]
[TD]Anytown, NY 11111[/TD]
[TD]anyemail@anyemail.com[/TD]
[/TR]
</tbody>[/TABLE]

...and convert it to this format:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]John Smith[/TD]
[TD]111 Any Road[/TD]
[TD]Anytown, NY 11111[/TD]
[TD](111) 111-1111[/TD]
[TD](222) 222-2222[/TD]
[TD]anyemail@anyemail.com[/TD]
[/TR]
</tbody>[/TABLE]

If I consider the 3 lines of original data to be 1 "record", the file I receive initially has hundreds of "records." The format of the original data will always be 2 columns and 3 rows. Is there a macros that can be created to help streamline this process? I'd truly appreciate any assistance given. (I also apologize, I don't have a full version of Excel at home and I'm not able to install anything on my work computer.)
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Jcd1078,

I can not make any sense out of your last two screenshots, in your reply #9.


Can you post a screenshot of the actual raw data worksheet?

And, can you post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

And, I will need detailed instructions.


If you are not able to give us screenshots:

You can upload your workbook to Box Net,

sensitive data changed

mark the workbook for sharing

and provide us with a link to your workbook.
 
Last edited:
Upvote 0
Upvote 0
The first two screen shots are the data. It wouldn't allow me to paste the table for both records at once. The third post is how I'd like the data to look.
 
Upvote 0
JCD1078,

I assume that worksheets Sheet1, and, Sheet2, already exist.

Sample worksheets:


Excel 2007
ABCD
1John Smith(111) 111-11111001
2111 Any Road(222) 222-2222
3Anytown, NY 11111anyemail@email.com
4Jane Smith(333) 333-33331001
5222 Any Road(444) 444-4444
6Anytown, NY 11111anyemail2@email.com
7
Sheet1



Excel 2007
ABCDEFGH
1
2
3
Sheet2


After the new macro (using two arrays in memory) in worksheet Sheet2:


Excel 2007
ABCDEFGH
1John Smith111 Any RoadAnytown, NY 11111(111) 111-1111(222) 222-2222anyemail@email.com1001
2Jane Smith222 Any RoadAnytown, NY 11111(333) 333-3333(444) 444-4444anyemail2@email.com1001
3
Sheet2


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub ReorgData_V2()
' hiker95, 09/11/2014, ME80784
Dim w1 As Worksheet, w2 As Worksheet
Dim a As Variant, o As Variant
Dim i As Long, j As Long, lr As Long, lc As Long
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w1
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  a = .Range(.Cells(1, 1), .Cells(lr, lc)).Value
  ReDim o(1 To lr / 3, 1 To 8)
End With
For i = 1 To lr Step 3
  j = j + 1
  o(j, 1) = a(i, 1)
  o(j, 2) = a(i + 1, 1)
  o(j, 3) = a(i + 2, 1)
  o(j, 4) = a(i, 2)
  o(j, 5) = a(i + 1, 2)
  o(j, 6) = a(i + 2, 2)
  o(j, 7) = a(i, 3)
  o(j, 8) = a(i, 4)
Next i
With w2
  .UsedRange.ClearContents
  .Cells(1, 1).Resize(lr / 3, 8).Value = o
  .UsedRange.Columns.AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ReorgData_V2 macro.
 
Last edited:
Upvote 0
JCD1078,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top