![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
I have some data below
at each change in column a i want to insert a colum at the top with the value of column a Bag Industries 123 CELLULOSE BAGS #9 250S Bag Industries 143 CELLULOSE BAGS #5 1000S BigBad 194 CELLULOSE BAGS #6 1000S Big Bad 190 CELLULOSE BAGS #3 1000S to look like Bag Industries 123 Bag Industries 123 CELLULOSE BAGS #9 250S Bag Industries 143 CELLULOSE BAGS #5 1000S BigBad BigBad 194 CELLULOSE BAGS #6 1000S BigBad 190 CELLULOSE BAGS #3 1000S and so on anyone got any code for this I cannot think right today! |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Apr 2002
Posts: 113
|
Conceptually:
Sort ColumnA CurrentName = "" CurrentNewColumn = 1 CurrentNewRow = 1 For each cell in ColumnA IF cell.value = "" then exit sub 'stop when no more data, otherwise select the used range in column A (see other postings) __IF cell.value <> CurrentName then _____'Create new column _____CurrentName = cell.value _____CurrentNewColumn = CurrentNewColumn + 1 _____CurrentNewRow = CurrentNewRow + 1 _____Cells(1,CurrentNewColumn).value = CurrentName __EndIF __Cells(CurrentNewRow,CurrentNewColumn).value = cell.value __CurrentNewRow = CurrentNewRow + 1 Next cell |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
yeah no that doesn't quite work but may give a couple of Ideas thanks
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
ok I wrote my own code for anyone thats interested
Sub InsertHeading() Dim CurrentName Application.ScreenUpdating = False Range("a2").Select Do Until ActiveCell.Value = "" CurrentName = ActiveCell ActiveCell.Rows("1:3").EntireRow.Select Selection.Insert Shift:=xlDown ActiveCell.Offset(1, 0).Select ActiveCell.Value = CurrentName Selection.Font.Bold = True ActiveCell.Offset(1, 0).Select repeat: ActiveCell.Offset(1, 0).Select If CurrentName = ActiveCell.Value Then GoTo repeat Loop Range("a2").Select End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|