PC Review


Reply
Thread Tools Rate Thread

Calculating column based on formula

 
 
S Himmelrich
Guest
Posts: n/a
 
      22nd Jan 2008
I'm getting an "Application-defined or object-defined error" on the
line below that I've identified...can anyone help me out on this?


Dim last7 As Long
last7 = Worksheets("Working Sheet").Cells(Rows.Count,
"J").End(xlUp).Row
Range("K1").Formula = "=IF(SUM('Working Sheet'!RC[1]/MACRO!G
$11$)),"",SUM('Working Sheet'!RC[1]/MACRO!G$11$)" <---LINE WITH ERROR
Range("K1").AutoFill Destination:=Range("K1:K" & last7)
 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      22nd Jan 2008
The $ signs are on the wrong side....

Range("K1").Formula = "=IF(SUM('Working
Sheet'!RC[1]/MACRO!$G$11)),"",SUM('Working Sheet'!RC[1]/MACRO!$G$11)"

Rick


"S Himmelrich" <(E-Mail Removed)> wrote in message
news:24ccf015-f0cd-4db9-abac-(E-Mail Removed)...
> I'm getting an "Application-defined or object-defined error" on the
> line below that I've identified...can anyone help me out on this?
>
>
> Dim last7 As Long
> last7 = Worksheets("Working Sheet").Cells(Rows.Count,
> "J").End(xlUp).Row
> Range("K1").Formula = "=IF(SUM('Working Sheet'!RC[1]/MACRO!G
> $11$)),"",SUM('Working Sheet'!RC[1]/MACRO!G$11$)" <---LINE WITH ERROR
> Range("K1").AutoFill Destination:=Range("K1:K" & last7)


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Jan 2008
You're mixing R1C1 reference style with A1 reference style.

If you decide to use all R1C1 reference style, then use .formulaR1C1 =

(and just a little help: $g$11 is r11c7)


S Himmelrich wrote:
>
> I'm getting an "Application-defined or object-defined error" on the
> line below that I've identified...can anyone help me out on this?
>
> Dim last7 As Long
> last7 = Worksheets("Working Sheet").Cells(Rows.Count,
> "J").End(xlUp).Row
> Range("K1").Formula = "=IF(SUM('Working Sheet'!RC[1]/MACRO!G
> $11$)),"",SUM('Working Sheet'!RC[1]/MACRO!G$11$)" <---LINE WITH ERROR
> Range("K1").AutoFill Destination:=Range("K1:K" & last7)


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Jan 2008
Ps. You have a couple of other things wrong with your formula.

If you need to have double quotes show up in your formula, then you'll need to
double them in your code.

And you don't need =sum(). You're just dividing one number by another.

And it looks like you're putting this all on Working Sheet, if that's true, then
you could try this:

Dim last7 As Long
With Worksheets("working sheet")
last7 = .Cells(.Rows.Count, "J").End(xlUp).Row
.Range("K1:K" & last7).FormulaR1C1 _
= "=IF(RC[1]/MACRO!r11c7,"""",RC[1]/MACRO!r11c7)"
End With

I'm not sure what you're doing with that formula, but maybe you were checking
for errors???

= "=IF(iserror(RC[1]/MACRO!r11c7),"""",RC[1]/MACRO!r11c7)"

is how I'd check.

S Himmelrich wrote:
>
> I'm getting an "Application-defined or object-defined error" on the
> line below that I've identified...can anyone help me out on this?
>
> Dim last7 As Long
> last7 = Worksheets("Working Sheet").Cells(Rows.Count,
> "J").End(xlUp).Row
> Range("K1").Formula = "=IF(SUM('Working Sheet'!RC[1]/MACRO!G
> $11$)),"",SUM('Working Sheet'!RC[1]/MACRO!G$11$)" <---LINE WITH ERROR
> Range("K1").AutoFill Destination:=Range("K1:K" & last7)


--

Dave Peterson
 
Reply With Quote
 
S Himmelrich
Guest
Posts: n/a
 
      22nd Jan 2008
Solution:

Dim rng As Range
Set rng = Range(Cells(1, "D"), Cells(Rows.Count, "D").End(xlUp))
rng.Offset(0, 7).Formula = "=IF(J1="""","""",SUM(J1/MACRO!$G$11))"
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Jan 2008
What happens if Macro!G11 is empty or is equal to 0?
Why use the =sum() function.
Why did the column change from J to D?



S Himmelrich wrote:
>
> Solution:
>
> Dim rng As Range
> Set rng = Range(Cells(1, "D"), Cells(Rows.Count, "D").End(xlUp))
> rng.Offset(0, 7).Formula = "=IF(J1="""","""",SUM(J1/MACRO!$G$11))"


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating sum based on value in adjacent column martin_pentreath@hotmail.com Microsoft Excel Misc 2 12th Dec 2006 01:33 PM
calculating other fields based on a formula in a report Michael Microsoft Access Reports 16 13th Jul 2005 01:08 PM
Calculating totals in a column based on a lookup in another column Michael Wright via OfficeKB.com Microsoft Excel Worksheet Functions 1 15th Apr 2005 09:52 AM
Calculating a field based on what is in another column acs68 Microsoft Excel Misc 3 28th Mar 2005 06:01 PM
Calculating values to column D with formula based on values column A spolk Microsoft Excel Programming 1 30th Apr 2004 06:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 PM.