correlation addin to macro :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

correlation addin to macro
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

ssaifan
Board Master


Joined: 29 Jul 2003
Posts: 133
Location: london
Flag: Uk

Status: Offline

 Reply with quote  

correlation addin to macro

i have the foll. macro which captures a column of data - as my data length
changes frequently the below macro does that ....

now i can capture 2 colums of data with that macro by changing column name..

now what i wana do is that ...

calculate the correlation coeff using correl function ...

can anyone tell me how to add that bit to my existing macro ...
below is the macro ......

--------------------------
Sub select_datastrategy()

Range("f1:f500").Select
Selection.ClearContents

Dim ulhc As String 'upper left hand corner
Dim lrhc As String 'lower right hand corner
Dim wdth As Integer 'true width in columns

ulhc = "$b$2"
wdth = 1

Application.Goto Range(ulhc) 'goto upper left hand corner
ActiveCell.Offset(0, wdth - 1).Select 'move to edge of data (column)
lrhc = Selection.End(xlDown).Address 'get address of lrhc

Range(ulhc & ":" & lrhc).Select
Selection.Copy
Sheets("sheet1").Select
Range("$f$2").Select
'ActiveCell.Select
Selection.PasteSpecial Paste:=xlValues, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

End Sub
-----------------
assume next column of data in column G ....


thanks

sam

Post Fri Sep 19, 2003 6:17 pm 
 View user's profile Send private message

parry
MrExcel MVP


Joined: 21 Aug 2002
Posts: 1332
Location: Wellington, New Zealand
Flag: Newzealand

Status: Offline

 Reply with quote  

Re: correlation addin to macro

Hi Sam, it just seems you want to replace contents in column f with those in column b (from b2 down until last row), then do a correl formula between column f and column g. Ive shortened the code somewhat (uyou dont really need to select things to transfer data) gives an example to get you started. I have just put the formula in cell h2 with range of rows 2-10 for cols f & g. Note that the correl appears to need two ranges that are identical size?

code:

Sub test()
Dim Rng As Range
'Copy data from b2 until last row in range into cell f1
Range("f1:f500").ClearContents
Set Rng = Range("b2:b" & Range("b65536").End(xlUp).Row)
Rng.Copy Range("f1")

'Insert correl function for f2:f10 and g2:g10 into cell h2
Range("h2").Formula = "=correl(f2:f10,g2:g10)"

End Sub


Post Fri Sep 19, 2003 6:55 pm 
 View user's profile Send private message

ssaifan
Board Master


Joined: 29 Jul 2003
Posts: 133
Location: london
Flag: Uk

Status: Offline

 Reply with quote  

Re: correlation addin to macro

that was gr8 ..
thanks

Post Fri Sep 19, 2003 7:15 pm 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.