Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Formula Cell Error

Hi all,

i have a problem with the following code, would appreciate if anyone can
give me some help on this. Basically everything works fine except for this
line:

Cells(i, 12).FormulaR1C1 = "=SUM(J" & StartCount & ":J" & EndCount & ")"

The cell will reflect "=SUM('J2':'J3')" instead of "=SUM(J2:J3)".

---------------------------------------------------------------------------------------------
Sub Test()

For i = 2 To 100 Step 1
Cells(i, 1).Select
If Cells(i, 1).Interior.ColorIndex = 2 Then
StartCount = ActiveCell.Row

ElseIf Cells(i, 1).Interior.ColorIndex = 37 Then
EndCount = ActiveCell.Row
Cells(i, 12).FormulaR1C1 = "=SUM(J" & StartCount & ":J" & EndCount & ")"

End If
Next i

End Sub
----------------------------------------------------------------------------------------

Thanks in advance

Rgds
Ray
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Formula Cell Error

Try the below. Your formula is not in R1C1 syntax

Cells(i, 12).Formula = "=SUM(J" & StartCount & ":J" & EndCount & ")"

If this post helps click Yes
---------------
Jacob Skaria


"swiftcode" wrote:

Hi all,

i have a problem with the following code, would appreciate if anyone can
give me some help on this. Basically everything works fine except for this
line:

Cells(i, 12).FormulaR1C1 = "=SUM(J" & StartCount & ":J" & EndCount & ")"

The cell will reflect "=SUM('J2':'J3')" instead of "=SUM(J2:J3)".

---------------------------------------------------------------------------------------------
Sub Test()

For i = 2 To 100 Step 1
Cells(i, 1).Select
If Cells(i, 1).Interior.ColorIndex = 2 Then
StartCount = ActiveCell.Row

ElseIf Cells(i, 1).Interior.ColorIndex = 37 Then
EndCount = ActiveCell.Row
Cells(i, 12).FormulaR1C1 = "=SUM(J" & StartCount & ":J" & EndCount & ")"

End If
Next i

End Sub
----------------------------------------------------------------------------------------

Thanks in advance

Rgds
Ray

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Formula Cell Error

Omit R1C1:

Cells(i, 12).Formula = "=SUM(J" & StartCount & ":J" & EndCount & ")"

Regards,
Stefi

€˛swiftcode€¯ ezt Ć*rta:

Hi all,

i have a problem with the following code, would appreciate if anyone can
give me some help on this. Basically everything works fine except for this
line:

Cells(i, 12).FormulaR1C1 = "=SUM(J" & StartCount & ":J" & EndCount & ")"

The cell will reflect "=SUM('J2':'J3')" instead of "=SUM(J2:J3)".

---------------------------------------------------------------------------------------------
Sub Test()

For i = 2 To 100 Step 1
Cells(i, 1).Select
If Cells(i, 1).Interior.ColorIndex = 2 Then
StartCount = ActiveCell.Row

ElseIf Cells(i, 1).Interior.ColorIndex = 37 Then
EndCount = ActiveCell.Row
Cells(i, 12).FormulaR1C1 = "=SUM(J" & StartCount & ":J" & EndCount & ")"

End If
Next i

End Sub
----------------------------------------------------------------------------------------

Thanks in advance

Rgds
Ray

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Formula Cell Error


There could be a number of reasons the code is failing. The obvious one
is you should use the property formula not formulaR1C1 since you are
using column J. I made some other changes.


Sub Test()

StartCount = 0
EndCount = 0
StartRow = 2
EndRow = 100
For i = StartRow To EndRow Step 1
If Range("A" & i).Interior.ColorIndex = 2 Then
StartCount = i
End If
If Range("A" & i).Interior.ColorIndex = 37 Then
EndCount = i
End If
If StartCount < 0 And EndCount < 0 Then
Range("L" & i).Formula = _
"=SUM(J" & StartCount & ":J" & EndCount & ")"
End If
Next i
If StartCount = 0 Or EndCount = 0 Then
MsgBox ("Did not find one of the colors")
End If

End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=155039

Microsoft Office Help

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Formula Cell Error

Hi Guys,

Thank you very much for all you solutions, it solved my problem.

You all have a great week ahead.

Rgds
Ray


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Formula Cell Error

You are welcome! Thanks for the feedback!

Sorry for the late answer but I've just now realized that my e-mail
notification doesn't work.


--
Regards!
Stefi



€˛swiftcode€¯ ezt Ć*rta:

Hi Guys,

Thank you very much for all you solutions, it solved my problem.

You all have a great week ahead.

Rgds
Ray

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
Error in cell formula Jerry Manner Excel Programming 12 April 7th 08 09:27 AM
Formula error - cell reference Sara Excel Discussion (Misc queries) 2 January 24th 08 04:38 PM
Error putting a formula in a cell with vba cristizet Excel Programming 4 April 22nd 07 02:11 PM
error in one cell and formula in other wolfgangea Excel Worksheet Functions 3 February 7th 07 07:55 PM
Formula expected end of statement error, typing formula into cell as part of VBA macro [email protected] Excel Programming 1 July 20th 06 07:58 PM


All times are GMT +1. The time now is 01:54 AM.

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"