PC Review


Reply
Thread Tools Rate Thread

Inserting a number of rows based on the number of columns filled bytext values

 
 
zorakramone
Guest
Posts: n/a
 
      30th Jul 2009
Hi

im trying to write a macro that will allow me to automat, inserting
rows based on the number of columns filled by names, then transpose
the names into the rows created.

E.g. from this...

Dave Peter Susan Luke Sam
Bob Brad Pedro
Joanna Pedro Danielle Jim


to this....

Dave Peter
Susan
Luke
Sam
Bob Brad
Pedro
Joanna Pedro
Danielle
Jim

any help would be kindly appreciated
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      30th Jul 2009
With your data starting from cell A1; try the below macro...with a sample..



Sub Macro()
Dim lngRow As Long, lngCol As Long, lngLastRow As Long

lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row + 2
lngRow = 1

Do While Trim(Cells(lngRow, 1)) <> ""
lngCol = 2
Cells(lngLastRow, 1) = Cells(lngRow, 1)
Do While Trim(Cells(lngRow, lngCol)) <> ""
Cells(lngLastRow, 2) = Cells(lngRow, lngCol)
lngCol = lngCol + 1
lngLastRow = lngLastRow + 1
Loop
lngRow = lngRow + 1
Loop

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"zorakramone" wrote:

> Hi
>
> im trying to write a macro that will allow me to automat, inserting
> rows based on the number of columns filled by names, then transpose
> the names into the rows created.
>
> E.g. from this...
>
> Dave Peter Susan Luke Sam
> Bob Brad Pedro
> Joanna Pedro Danielle Jim
>
>
> to this....
>
> Dave Peter
> Susan
> Luke
> Sam
> Bob Brad
> Pedro
> Joanna Pedro
> Danielle
> Jim
>
> any help would be kindly appreciated
>

 
Reply With Quote
 
 
 
 
Lars-Åke Aspelin
Guest
Posts: n/a
 
      30th Jul 2009
On Thu, 30 Jul 2009 02:41:04 -0700 (PDT), zorakramone
<(E-Mail Removed)> wrote:

>Hi
>
>im trying to write a macro that will allow me to automat, inserting
>rows based on the number of columns filled by names, then transpose
>the names into the rows created.
>
>E.g. from this...
>
>Dave Peter Susan Luke Sam
>Bob Brad Pedro
>Joanna Pedro Danielle Jim
>
>
>to this....
>
>Dave Peter
> Susan
> Luke
> Sam
>Bob Brad
> Pedro
>Joanna Pedro
> Danielle
> Jim
>
>any help would be kindly appreciated


Try this macro:

Sub zorakramone()
first_row = 1
last_row = Cells(1, 1).End(xlDown).Row
next_new_row = last_row + 1
For r = first_row To last_row
first_column = 2
last_column = Cells(r, 255).End(xlToLeft).Column
Rows(next_new_row).Insert shift:=xlDown
Cells(next_new_row, 1) = Cells(r, 1)
If last_column = 1 Then next_new_row = next_new_row + 1
For c = first_column To last_column
If c > 2 Then Rows(next_new_row).Insert shift:=xlDown
Cells(next_new_row, 2) = Cells(r, c)
next_new_row = next_new_row + 1
Next c
Next r
Rows(first_row & ":" & last_row).Delete shift:=xlUp
End Sub

You can comment out the last statement (Delete) until you have
verified that the result is as expected.

Hope this helps / Lars-Åke
 
Reply With Quote
 
keiji kounoike
Guest
Posts: n/a
 
      30th Jul 2009
I assumed your data start at A1. try this one.

Sub movetest()
Dim Stcell As Range, Encell As Range, Nxcell As Range
Dim n As Long

Application.ScreenUpdating = False
Set Stcell = Cells(1, "A")
Do While (Stcell <> "")
Set Encell = Cells(Stcell.Row, Cells.Columns.Count).End(xlToLeft)
n = Range(Stcell, Encell).Cells.Count
If n > 2 Then
Set Nxcell = Stcell.Offset(1, 0)
Nxcell.Resize(n - 2).EntireRow.Insert
Stcell.Offset(0, 2).Resize(, n - 2).Copy
Stcell.Offset(1, 0).PasteSpecial Transpose:=True
Stcell.Offset(0, 2).Resize(, n - 2).ClearContents
Set Stcell = Nxcell
Else
Set Stcell = Stcell.Offset(1, 0)
End If
Loop

On Error Resume Next
For Each Stcell In Columns("A").SpecialCells(xlCellTypeBlanks)
Stcell.EntireRow.Delete
Next

End Sub

Keiji


zorakramone wrote:
> Hi
>
> im trying to write a macro that will allow me to automat, inserting
> rows based on the number of columns filled by names, then transpose
> the names into the rows created.
>
> E.g. from this...
>
> Dave Peter Susan Luke Sam
> Bob Brad Pedro
> Joanna Pedro Danielle Jim
>
>
> to this....
>
> Dave Peter
> Susan
> Luke
> Sam
> Bob Brad
> Pedro
> Joanna Pedro
> Danielle
> Jim
>
> any help would be kindly appreciated

 
Reply With Quote
 
zorakramone
Guest
Posts: n/a
 
      3rd Aug 2009
Hey Guys

thanks a lot for your all your help
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 01:52 AM
Extracting Values and inserting Rows/Values VexedFist Microsoft Excel Programming 3 22nd Apr 2008 02:37 PM
Filled cells dont appear as filled =?Utf-8?B?U01JTExT?= Microsoft Excel Misc 6 18th Oct 2007 05:28 PM
zero filled changed to non-zero filled JPM Microsoft Excel Programming 1 20th Jul 2006 03:06 PM
Columns to rows/ Rows to columns Janet Microsoft Excel Misc 0 11th Sep 2003 02:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:51 PM.