Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to automatically validate some data and am trying to do a sum on
a variable range but it doesn't work! ActiveCell.FormulaR1C1 = "=SUM(R[-myvariable]C:R[-1]C)" where myvariable is the number of rows to sum Can anyone help? Thanks, Dean Code below: (probably a very inefficient and long winded way of doing it but as long as it works I'll be happy!) Sub Loop1() Columns("I:I").Select Selection.Insert Shift:=xlToRight Range("I1").Select Range("I3").Select Do ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],""Yes"",""No"")" ActiveCell.Offset(1, 0).Select Loop Until IsEmpty(ActiveCell.Offset(0, 1)) Range("I1").Select Columns("J:J").Select Selection.Insert Shift:=xlToRight Columns("I:I").Select Selection.Copy Columns("J:J").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Columns("I:I").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Range("I1").Select Range("I3").Select rdlA = 0 Do If ActiveCell.FormulaR1C1 = "Yes" Then rdlA = rdlA + 1 ElseIf ActiveCell.FormulaR1C1 = "No" Then Selection.EntireRow.Insert If rdlA 1 Then ActiveCell.Offset(0, 4).Select 'error here ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(1, 7).Select Selection.EntireRow.Insert rdlA = 0 Else End If Else MsgBox "Error" End If ActiveCell.Offset(1, 0).Select Loop Until IsEmpty(ActiveCell.Offset(0, 1)) Range("I2").Select ActiveCell.FormulaR1C1 = "Yes" Range("I1").Select End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
ActiveCell.FormulaR1C1 = "=SUM(R[-" & myvariable & "]C:R[-1]C)"
Dean@ERYC wrote: I am trying to automatically validate some data and am trying to do a sum on a variable range but it doesn't work! ActiveCell.FormulaR1C1 = "=SUM(R[-myvariable]C:R[-1]C)" where myvariable is the number of rows to sum Can anyone help? Thanks, Dean Code below: (probably a very inefficient and long winded way of doing it but as long as it works I'll be happy!) Sub Loop1() Columns("I:I").Select Selection.Insert Shift:=xlToRight Range("I1").Select Range("I3").Select Do ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],""Yes"",""No"")" ActiveCell.Offset(1, 0).Select Loop Until IsEmpty(ActiveCell.Offset(0, 1)) Range("I1").Select Columns("J:J").Select Selection.Insert Shift:=xlToRight Columns("I:I").Select Selection.Copy Columns("J:J").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Columns("I:I").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Range("I1").Select Range("I3").Select rdlA = 0 Do If ActiveCell.FormulaR1C1 = "Yes" Then rdlA = rdlA + 1 ElseIf ActiveCell.FormulaR1C1 = "No" Then Selection.EntireRow.Insert If rdlA 1 Then ActiveCell.Offset(0, 4).Select 'error here ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(1, 7).Select Selection.EntireRow.Insert rdlA = 0 Else End If Else MsgBox "Error" End If ActiveCell.Offset(1, 0).Select Loop Until IsEmpty(ActiveCell.Offset(0, 1)) Range("I2").Select ActiveCell.FormulaR1C1 = "Yes" Range("I1").Select End Sub -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
ActiveCell.FormulaR1C1 = "=SUM(R[-" & myvariable & "]C:R[-1]C)"
-- Regards, Tom Ogilvy "Dean@ERYC" wrote: I am trying to automatically validate some data and am trying to do a sum on a variable range but it doesn't work! ActiveCell.FormulaR1C1 = "=SUM(R[-myvariable]C:R[-1]C)" where myvariable is the number of rows to sum Can anyone help? Thanks, Dean Code below: (probably a very inefficient and long winded way of doing it but as long as it works I'll be happy!) Sub Loop1() Columns("I:I").Select Selection.Insert Shift:=xlToRight Range("I1").Select Range("I3").Select Do ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],""Yes"",""No"")" ActiveCell.Offset(1, 0).Select Loop Until IsEmpty(ActiveCell.Offset(0, 1)) Range("I1").Select Columns("J:J").Select Selection.Insert Shift:=xlToRight Columns("I:I").Select Selection.Copy Columns("J:J").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Columns("I:I").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Range("I1").Select Range("I3").Select rdlA = 0 Do If ActiveCell.FormulaR1C1 = "Yes" Then rdlA = rdlA + 1 ElseIf ActiveCell.FormulaR1C1 = "No" Then Selection.EntireRow.Insert If rdlA 1 Then ActiveCell.Offset(0, 4).Select 'error here ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=SUM(R[-rdlA]C:R[-1]C)" ActiveCell.Offset(1, 7).Select Selection.EntireRow.Insert rdlA = 0 Else End If Else MsgBox "Error" End If ActiveCell.Offset(1, 0).Select Loop Until IsEmpty(ActiveCell.Offset(0, 1)) Range("I2").Select ActiveCell.FormulaR1C1 = "Yes" Range("I1").Select End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Runtime Error '91' Object variable or With block variable not set | Excel Discussion (Misc queries) | |||
Getting inconsistent Error 91-Object variable or With block variable not set | Excel Programming | |||
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? | Excel Worksheet Functions | |||
Run-time error '91': "Object variable or With block variable not set | Excel Programming | |||
Cells.Find error Object variable or With block variable not set | Excel Programming |