Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default R[1]C[1] with a variable

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default R[1]C[1] with a variable

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default R[1]C[1] with a variable

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
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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Getting inconsistent Error 91-Object variable or With block variable not set mfq Excel Programming 0 December 14th 05 06:08 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 11:43 PM.

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

About Us

"It's about Microsoft Excel"