View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Counting rows in Excel spreadsheet.

I said you don't need to do both selects. In this case, you need to use the
cells.select

Sub Prod_Abstract()
'
' Prod_Abstract Macro
' Macro recorded 3/9/2006 by JBW
'
Dim lastrow As Long
Columns("I:I").Select
Selection.Insert Shift:=xlToRight
Range("I1").Select
ActiveCell.FormulaR1C1 = "MMCFE"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=SUM((RC[-2]*6+RC[-1])/1000)"
Selection.Copy
Application.CutCopyMode = False
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Selection.AutoFill Destination:=Range("I2:I" & lastrow)
Cells.Select
Selection.Sort Key1:=Range("I2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns("G:I").Select
Selection.NumberFormat = "#,##0"
End Sub

--
Regards,
Tom Ogilvy

"Jim15" wrote:


Thanks for the solution but the sort at the end of the macro no longer
works.

Here is the code.

Sub Prod_Abstract()
'
' Prod_Abstract Macro
' Macro recorded 3/9/2006 by JBW
'
Dim lastrow As Long
Columns("I:I").Select
Selection.Insert Shift:=xlToRight
Range("I1").Select
ActiveCell.FormulaR1C1 = "MMCFE"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=SUM((RC[-2]*6+RC[-1])/1000)"
Selection.Copy
Application.CutCopyMode = False
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Selection.AutoFill Destination:=Range("I2:I" & lastrow)
Range("I2:I" & lastrow).Select
Selection.Sort Key1:=Range("I2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal
Columns("G:I").Select
Selection.NumberFormat = "#,##0"
End Sub


--
Jim15
------------------------------------------------------------------------
Jim15's Profile: http://www.excelforum.com/member.php...o&userid=26300
View this thread: http://www.excelforum.com/showthread...hreadid=547911