Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro to Number New Rows Inserted Into Table?

The macro below shows all the rows on a sheet with an AutoFilter and then
inserts a row at the Active Cell:

Sub ShowAllRecordsAndInsertRows()
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If

With ActiveCell
Selection.EntireRow.Insert

End With
End Sub

In the first column (A) of the sheet, however, I have each row numbered from
one to whatever the last record is (currently it's 7699) so that I can always
restore the sheet to its original order easily. How can I augment my macro so
that it also inputs a number in the first cell of the new row that is between
the numbers above and below it?

I figure the easiest way is for the macro to add the values in the adjacent
cells in column A over and under the new row, divide that sum by two, and
return that value into the cell in column A in the new row. (It doesn't
really matter what the numbers in column A are as long as they reflect the
correct original order of the table).

I'm a novice at VBA, so I have no idea how to do this. Could anyone please
help?

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default Macro to Number New Rows Inserted Into Table?

Lysander,

Sub ShowAllRecordsAndInsertRows2()
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If

ActiveCell.EntireRow.Insert

Cells(ActiveCell.Row, 1).Value = _
(Cells(ActiveCell.Row - 1, 1).Value + _
Cells(ActiveCell.Row + 1, 1).Value) / 2

End Sub


HTH,
Bernie
MS Excel MVP


"Lysander Stark" wrote in message
...
The macro below shows all the rows on a sheet with an AutoFilter and then
inserts a row at the Active Cell:

Sub ShowAllRecordsAndInsertRows()
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If

With ActiveCell
Selection.EntireRow.Insert

End With
End Sub

In the first column (A) of the sheet, however, I have each row numbered from
one to whatever the last record is (currently it's 7699) so that I can always
restore the sheet to its original order easily. How can I augment my macro so
that it also inputs a number in the first cell of the new row that is between
the numbers above and below it?

I figure the easiest way is for the macro to add the values in the adjacent
cells in column A over and under the new row, divide that sum by two, and
return that value into the cell in column A in the new row. (It doesn't
really matter what the numbers in column A are as long as they reflect the
correct original order of the table).

I'm a novice at VBA, so I have no idea how to do this. Could anyone please
help?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro to Number New Rows Inserted Into Table?

Bernie:

Thank you so much--this does exactly what I needed it to do. I really
appreciate your help! You've made the rest of this day a lot easier!

"Bernie Deitrick" wrote:

Lysander,

Sub ShowAllRecordsAndInsertRows2()
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If

ActiveCell.EntireRow.Insert

Cells(ActiveCell.Row, 1).Value = _
(Cells(ActiveCell.Row - 1, 1).Value + _
Cells(ActiveCell.Row + 1, 1).Value) / 2

End Sub


HTH,
Bernie
MS Excel MVP


"Lysander Stark" wrote in message
...
The macro below shows all the rows on a sheet with an AutoFilter and then
inserts a row at the Active Cell:

Sub ShowAllRecordsAndInsertRows()
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If

With ActiveCell
Selection.EntireRow.Insert

End With
End Sub

In the first column (A) of the sheet, however, I have each row numbered from
one to whatever the last record is (currently it's 7699) so that I can always
restore the sheet to its original order easily. How can I augment my macro so
that it also inputs a number in the first cell of the new row that is between
the numbers above and below it?

I figure the easiest way is for the macro to add the values in the adjacent
cells in column A over and under the new row, divide that sum by two, and
return that value into the cell in column A in the new row. (It doesn't
really matter what the numbers in column A are as long as they reflect the
correct original order of the table).

I'm a novice at VBA, so I have no idea how to do this. Could anyone please
help?




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
updating pivot table to include additional rows Ellen Excel Discussion (Misc queries) 8 July 15th 08 01:33 PM
Macro Help - Indefinite Rows piano.lisa Excel Discussion (Misc queries) 3 August 16th 06 05:47 PM
Need to Improve Code Copying/Pasting Between Workbooks David Excel Discussion (Misc queries) 1 January 6th 06 03:56 AM
pivot table error (25000 rows!!) Craig_Richards Excel Discussion (Misc queries) 1 November 13th 05 06:52 PM
Macro Help In Excel welshlad Excel Discussion (Misc queries) 14 October 26th 05 02:34 PM


All times are GMT +1. The time now is 06:45 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"