PC Review


Reply
Thread Tools Rate Thread

calculate a correlation with ranges

 
 
=?Utf-8?B?UGFjbw==?=
Guest
Posts: n/a
 
      20th Sep 2007
All i need is to calculate a correlation of two ranges and assign it to a
variable. I tried this but i get an 91 error (object or with block not set):

dim correlation as range
Set correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"

but, if i replace "correlation" by range("a1"), then it works fine.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      20th Sep 2007
dim correlation as range
set correlation = Range("A1")
correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"

--
Regards,
Tom Ogilvy


"Paco" wrote:

> All i need is to calculate a correlation of two ranges and assign it to a
> variable. I tried this but i get an 91 error (object or with block not set):
>
> dim correlation as range
> Set correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"
>
> but, if i replace "correlation" by range("a1"), then it works fine.
>

 
Reply With Quote
 
=?Utf-8?B?UGFjbw==?=
Guest
Posts: n/a
 
      20th Sep 2007
Hi Tom! you see, I cannot do that. My database changes so I don't know where
will i have empty cells. Do you know how can I assign that correlation value
to a variable (that doesn't require a cell)?

"Tom Ogilvy" wrote:

> dim correlation as range
> set correlation = Range("A1")
> correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Paco" wrote:
>
> > All i need is to calculate a correlation of two ranges and assign it to a
> > variable. I tried this but i get an 91 error (object or with block not set):
> >
> > dim correlation as range
> > Set correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"
> >
> > but, if i replace "correlation" by range("a1"), then it works fine.
> >

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      20th Sep 2007
I don't know what i and j contain or what inSerie is. These may be defined
names.

But if you look at the example in help for the correl worksheet function you
see the formula

=CORREL(A2:A6,B2:B6)

to do that in VBA

Dim correlation as double
correlation = application.Correl(Range("A2:A6"), Range("B2:B6"))


Just to demonstrate from the immediate window in the VBE:

correlation = application.Correl(Range("A2:A6"), Range("B2:B6"))
? correlation
0.997054485501581

A2:A6 and B2:B2 contain the numbers shown in the help example.

if Inserie1 is a named range and inserie2 is a named range then it would be

Dim i as Long, j as Long, correlation as double
i = 1
j = 1
correlation = application.Correl(Range("inSerie" & i), Range("inSerie" & j))

--
Regards,
Tom Ogilvy



"Paco" wrote:

> Hi Tom! you see, I cannot do that. My database changes so I don't know where
> will i have empty cells. Do you know how can I assign that correlation value
> to a variable (that doesn't require a cell)?
>
> "Tom Ogilvy" wrote:
>
> > dim correlation as range
> > set correlation = Range("A1")
> > correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> >
> > "Paco" wrote:
> >
> > > All i need is to calculate a correlation of two ranges and assign it to a
> > > variable. I tried this but i get an 91 error (object or with block not set):
> > >
> > > dim correlation as range
> > > Set correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"
> > >
> > > but, if i replace "correlation" by range("a1"), then it works fine.
> > >

 
Reply With Quote
 
=?Utf-8?B?UGFjbw==?=
Guest
Posts: n/a
 
      20th Sep 2007
This is great!!! thanks a lot Tom!!! I've been trying for days!!!

"Tom Ogilvy" wrote:

> I don't know what i and j contain or what inSerie is. These may be defined
> names.
>
> But if you look at the example in help for the correl worksheet function you
> see the formula
>
> =CORREL(A2:A6,B2:B6)
>
> to do that in VBA
>
> Dim correlation as double
> correlation = application.Correl(Range("A2:A6"), Range("B2:B6"))
>
>
> Just to demonstrate from the immediate window in the VBE:
>
> correlation = application.Correl(Range("A2:A6"), Range("B2:B6"))
> ? correlation
> 0.997054485501581
>
> A2:A6 and B2:B2 contain the numbers shown in the help example.
>
> if Inserie1 is a named range and inserie2 is a named range then it would be
>
> Dim i as Long, j as Long, correlation as double
> i = 1
> j = 1
> correlation = application.Correl(Range("inSerie" & i), Range("inSerie" & j))
>
> --
> Regards,
> Tom Ogilvy
>
>
>
> "Paco" wrote:
>
> > Hi Tom! you see, I cannot do that. My database changes so I don't know where
> > will i have empty cells. Do you know how can I assign that correlation value
> > to a variable (that doesn't require a cell)?
> >
> > "Tom Ogilvy" wrote:
> >
> > > dim correlation as range
> > > set correlation = Range("A1")
> > > correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"
> > >
> > > --
> > > Regards,
> > > Tom Ogilvy
> > >
> > >
> > > "Paco" wrote:
> > >
> > > > All i need is to calculate a correlation of two ranges and assign it to a
> > > > variable. I tried this but i get an 91 error (object or with block not set):
> > > >
> > > > dim correlation as range
> > > > Set correlation.Formula = "=correl(inSerie" & i & ",inSerie" & j & ")"
> > > >
> > > > but, if i replace "correlation" by range("a1"), then it works fine.
> > > >

 
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
how i calculate pearson correlation coefficient for excel graph =?Utf-8?B?dW5pdmVyc2l0eSBzdHVkZW50IHRoYXQgaXMgbG9z Microsoft Excel Charting 11 18th Sep 2006 04:04 PM
calculate ranges Bob Bedford Microsoft Excel Worksheet Functions 6 25th Nov 2005 11:03 AM
How do I calculate an offset between two ranges? mo childs Microsoft Excel Programming 4 19th Oct 2005 11:27 AM
how to calculate number ranges =?Utf-8?B?TG9yaQ==?= Microsoft Excel Worksheet Functions 2 2nd May 2005 05:05 PM
How do I use the "Correlation" dialog box with multiple ranges? =?Utf-8?B?UGF1bGY2?= Microsoft Excel Misc 1 4th Apr 2005 09:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:08 PM.