If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Macro-total a column with different row sizes
I’m trying to create a macro and I’m having trouble with the last part. I
want to total a column (E) but the number of rows will vary day to day. For example this totaled today’s file with 726 rows but tomorrow’s file might have 800 or 500 rows. How do I account for the various row size? Range("E13").Select Selection.End(xlDown).Select Range("E726").Select Selection.FormulaR1C1 = "=SUM(R[-724]C:R[-1]C)" |
#2
|
|||
|
|||
Macro-total a column with different row sizes
On May 13, 1:37*am, Michele wrote:
I’m trying to create a macro and I’m having trouble with the last part. *I want to total a column (E) but the number of rows will vary day to day. *For example this totaled today’s file with 726 rows but tomorrow’s file might have 800 or 500 rows. *How do I account for the various row size? * * Range("E13").Select * * Selection.End(xlDown).Select * * Range("E726").Select * * Selection.FormulaR1C1 = "=SUM(R[-724]C:R[-1]C)" something like this Sub n() Range("E13").Select Selection.End(xlDown).Select Dim frow As Integer Dim lrow As Integer frow = Selection.Cells(1, 1).Row 'you have made it as 13 lrow = Selection.Rows.Count + frow - 1 Dim n As Integer n = lrow - frow + 2 Cells(lrow + 2, "E").FormulaR1C1 = "=SUM(R[-" & n & "]C:R[-2]C)" End Sub |
Thread Tools | |
Display Modes | |
|
|