Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 184
Default Macro-delete & move heading

I was hoping someone could help me with following macro code:

I have two columns, in the first there are headings in the first row and in
the second there is the detail for that heading.
For example:
A B
Fruits
Orange
Banana
Peach
Total
I would like a macro code that will move Fruit from the first row and move
it in front of Total
A B

Orange
Banana
Peach
Fruit Total

Any help would be greatly appreciate it.

Thank you so much in advance.

Regards-Nikki

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,069
Default Macro-delete & move heading

Try this macro. From your post I gathered that the first heading is in cell
A1. If that's not so, edit the line Const FirstCell = "A1" to refer to
the correct cell.

Sub MoveHdg()
Const FirstCell = "A1"
Dim Txt As String, StopRow As Long
StopRow& = Range("B" & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(FirstCell).Activate
Do While ActiveCell.Row < StopRow&
If Len(ActiveCell.Value) = 0 Then
ActiveCell.End(xlDown).Activate
End If
Txt$ = ActiveCell.Value
ActiveCell.Value = vbNullString
Do While Trim(LCase(ActiveCell.Offset(0, 1).Value)) < "total"
ActiveCell.Offset(1, 0).Activate
Loop
ActiveCell.Value = Txt$
ActiveCell.Offset(1, 0).Activate
DoEvents
Loop
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Hope this helps,

Hutch

"Nikki" wrote:

I was hoping someone could help me with following macro code:

I have two columns, in the first there are headings in the first row and in
the second there is the detail for that heading.
For example:
A B
Fruits
Orange
Banana
Peach
Total
I would like a macro code that will move Fruit from the first row and move
it in front of Total
A B

Orange
Banana
Peach
Fruit Total

Any help would be greatly appreciate it.

Thank you so much in advance.

Regards-Nikki

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 184
Default Macro-delete & move heading

Thank you so much Tom. It worked prefectly.
have a wonderful day.

"Tom Hutchins" wrote:

Try this macro. From your post I gathered that the first heading is in cell
A1. If that's not so, edit the line Const FirstCell = "A1" to refer to
the correct cell.

Sub MoveHdg()
Const FirstCell = "A1"
Dim Txt As String, StopRow As Long
StopRow& = Range("B" & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(FirstCell).Activate
Do While ActiveCell.Row < StopRow&
If Len(ActiveCell.Value) = 0 Then
ActiveCell.End(xlDown).Activate
End If
Txt$ = ActiveCell.Value
ActiveCell.Value = vbNullString
Do While Trim(LCase(ActiveCell.Offset(0, 1).Value)) < "total"
ActiveCell.Offset(1, 0).Activate
Loop
ActiveCell.Value = Txt$
ActiveCell.Offset(1, 0).Activate
DoEvents
Loop
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Hope this helps,

Hutch

"Nikki" wrote:

I was hoping someone could help me with following macro code:

I have two columns, in the first there are headings in the first row and in
the second there is the detail for that heading.
For example:
A B
Fruits
Orange
Banana
Peach
Total
I would like a macro code that will move Fruit from the first row and move
it in front of Total
A B

Orange
Banana
Peach
Fruit Total

Any help would be greatly appreciate it.

Thank you so much in advance.

Regards-Nikki

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is my Macro delete key greyed out? rogerjcfinch Excel Discussion (Misc queries) 3 July 22nd 06 06:04 PM
Macro to delete workbook after use Nigel Excel Discussion (Misc queries) 1 June 22nd 06 08:49 PM
Delete Duplicate Rows Macro Question elfmajesty Excel Discussion (Misc queries) 1 June 17th 06 01:12 AM
Macro won't move in proper progression Laurahoney Excel Discussion (Misc queries) 1 November 23rd 05 07:18 PM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM


All times are GMT +1. The time now is 08:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"