Turn 1 huge column into 7 with rows separated by certain values

Gingertrees

Well-known Member
Joined
Sep 21, 2009
Messages
697
Organizing addresses again, I have a long list with up to 7 rows per entry. I have labeled this thusly:
Code:
[COLUMN A..............][.B..]
SMITH'S PARTS............1
300 MAIN ST, ABE NC......2
PHONE: 300-222-2222......3
FAX......................4
WEB: WWW.____.NET........5
CONTACT: JON SMITH.......6
GET DIRECTIONS...........7
OAKVILLE STORE...........1
12 ARBOR RD, BLISS ID....2
PHONE: 800-345-2222......3
FAX......................4
CONTACT: JERRY JACK......6
GET DIRECTIONS...........7

Since not all businesses have Fax info, or a website, sometime there is no line 4 or 5, so the numbers go like this:
...1
...2
...3
...6
...7
...1
...2
...3
...4
...6
...7
(etc)
This is in one big column of numbers (column B). There's always a 1,2,3, 6,and 7. The middle ones get tricky.

I want to change from that column to rows with 7 columns.
IS there some way (vlookup? VBA?) that Excel can know "7=last column in a row, start new row". Also, "4 does not exist, skip to next cell"


Name.......Addr........Phone...Fax...Web...Contact...Directions

Crosspost at the bottom of a long and ignored thread:
http://www.mrexcel.com/forum/showthread.php?t=613879&page=2
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Select B1 and try this, making sure you have six empty columns to the right.
(C-H)

Code:
Sub Macro1()
'
' Macro1 Macro
'
'

'
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.Cut
    ActiveCell.Offset(-1, 1).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(2, -1).Range("A1").Select
    Selection.Cut
    ActiveCell.Offset(-2, 2).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(3, -2).Range("A1").Select
    Selection.Cut
    ActiveCell.Offset(-3, 3).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(4, -3).Range("A1").Select
    Selection.Cut
    ActiveCell.Offset(-4, 4).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(5, -4).Range("A1").Select
    Selection.Cut
    ActiveCell.Offset(-5, 5).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(6, -5).Range("A1").Select
    Selection.Cut
    ActiveCell.Offset(-6, 6).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(1, -6).Range("A1:A6").Select
    Selection.Delete Shift:=xlUp
    ActiveCell.Select
End Sub
 
Upvote 0
Hi,

For a formula alternative maybe try something like this:
Excel Workbook
ABCDEFGHIJK
1SMITH'S PARTS1NameAddrPhoneFaxWebContactDirections
2300 MAIN ST, ABE NC27SMITH'S PARTS300 MAIN ST, ABE NCPHONE: 300-222-2222FAX: 2353WEB: WWW.____.NETCONTACT: JON SMITHGET DIRECTIONS
3PHONE: 300-222-2222312OAKVILLE STORE12 ARBOR RD, BLISS IDPHONE: 800-345-2222CONTACT: JERRY JACKGET DIRECTIONS
4FAX: 23534
5WEB: WWW.____.NET5
6CONTACT: JON SMITH6
7GET DIRECTIONS7
8OAKVILLE STORE1
912 ARBOR RD, BLISS ID2
10PHONE: 800-345-22223
11CONTACT: JERRY JACK6
12GET DIRECTIONS7
Sheet1
Excel 2010
Cell Formulas
RangeFormula
E2=IFERROR(INDEX(INDEX($A:$A,$D1+1):INDEX($A:$A,$D2),MATCH(COLUMNS($E$1:E$1),INDEX($B:$B,$D1+1):INDEX($B:$B,$D2),0)),"")
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
  • Drag down the formula in D2 (you need to use CTRL-SHIFT-ENTER rather than just ENTER for this one as it is an array formula). Also, change both 12's in the D2 formula to the last row in your column.
  • Drag across the formula in E2 to K2 and then down (this just needs the normal ENTER)
 
Last edited:
Upvote 0
For a slightly simplified version of the E2 formula, perhaps:

=IFERROR(INDEX($A:$A,MATCH(COLUMNS($E$1:E$1),INDEX($B:$B,$D1+1):INDEX($B:$B,$D2),0)+$D1),"")
 
Upvote 0
circledchicken: you are the BOMB! I spent far too long trying to get an insert-row macro to work. Thank you thank you thank you!!
 
Upvote 0
I spent far too long trying to get an insert-row macro to work.
If you still wanted to do this with a macro and avoid the formulas, I am pretty sure this macro works the way you want...

Code:
Sub DistributeDataAcrossColumns()
  Dim X As Long, LastRow As Long, NameRow As Long, Sevens As Range
  Const StartRow As Long = 1
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  Columns("B").Replace 7, "=7", xlWhole
  Set Sevens = Columns("B").SpecialCells(xlFormulas)
  NameRow = StartRow
  For X = StartRow To LastRow
    Cells(NameRow, Cells(X, "B").Value + 4).Value = Cells(X, "A")
    If Cells(X, "B").Value = 7 Then NameRow = NameRow + 1
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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