Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default worksheet function with two ranges

I want to calculate the stdev of (colA - colB) in VBA code without
creating a new column. My attempted code below gives me a type
mismatch. Does anyone know how I would do it?

Public Sub calcStdev()

Dim myRangeAct As Range
Dim myRangeMod As Range

Set myRangeAct = Range(Cells(1, 1), Cells(100, 1))
Set myRangeMod = Range(Cells(1, 2), Cells(100, 2))

Debug.Print Application.WorksheetFunction.StDevP(myRangeAct)
Debug.Print Application.WorksheetFunction.StDevP(myRangeMod)

'GET TYPE MISMATCH
Debug.Print Application.WorksheetFunction.StDevP(myRangeAct -
myRangeMod)

End Sub

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default worksheet function with two ranges

Try...

msgbox [stdevp(MRng)]

Where MRng is a named range.
Add more references if needed.


Regards
Robert McCurdy
"pb" wrote in message oups.com...
I want to calculate the stdev of (colA - colB) in VBA code without
creating a new column. My attempted code below gives me a type
mismatch. Does anyone know how I would do it?

Public Sub calcStdev()

Dim myRangeAct As Range
Dim myRangeMod As Range

Set myRangeAct = Range(Cells(1, 1), Cells(100, 1))
Set myRangeMod = Range(Cells(1, 2), Cells(100, 2))

Debug.Print Application.WorksheetFunction.StDevP(myRangeAct)
Debug.Print Application.WorksheetFunction.StDevP(myRangeMod)

'GET TYPE MISMATCH
Debug.Print Application.WorksheetFunction.StDevP(myRangeAct -
myRangeMod)

End Sub

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 762
Default worksheet function with two ranges

pb -

A non-VBA solution is

=STDEVP(A1:A100-B1:B100)

array-entered (Control+Shift+Enter instead of Enter).

- Mike
http://www.mikemiddleton.com


"pb" wrote in message
oups.com...
I want to calculate the stdev of (colA - colB) in VBA code without
creating a new column. My attempted code below gives me a type
mismatch. Does anyone know how I would do it?

Public Sub calcStdev()

Dim myRangeAct As Range
Dim myRangeMod As Range

Set myRangeAct = Range(Cells(1, 1), Cells(100, 1))
Set myRangeMod = Range(Cells(1, 2), Cells(100, 2))

Debug.Print Application.WorksheetFunction.StDevP(myRangeAct)
Debug.Print Application.WorksheetFunction.StDevP(myRangeMod)

'GET TYPE MISMATCH
Debug.Print Application.WorksheetFunction.StDevP(myRangeAct -
myRangeMod)

End Sub

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default worksheet function with two ranges

Hello,

In VBA the operator "-" is not defined on ranges.

A workaround:
Sub calcStdev()

Dim myRangeAct As Range
Dim myRangeMod As Range
Dim a(1 To 100) As Double
Dim i As Long

Set myRangeAct = Range(Cells(1, 1), Cells(100, 1))
Set myRangeMod = Range(Cells(1, 2), Cells(100, 2))

Debug.Print Application.WorksheetFunction.StDevP(myRangeAct)
Debug.Print Application.WorksheetFunction.StDevP(myRangeMod)

For i = 1 To 100
a(i) = myRangeAct(i) - myRangeMod(i)
Next i

Debug.Print Application.WorksheetFunction.StDevP(a)

End Sub

Regards,
Bernd

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
IF Function with different ranges. GEM Excel Discussion (Misc queries) 1 June 16th 09 08:06 PM
Sum over ranges on another worksheet jmcclain Excel Worksheet Functions 4 October 30th 08 05:14 PM
Copy Worksheet plus ranges Ray Batig Excel Programming 2 March 16th 05 10:56 PM
Vlookup with 2 ranges in one worksheet Eelco Wiertsema Excel Worksheet Functions 5 February 18th 05 07:57 PM
How to loop through all ranges in a worksheet Nanette[_2_] Excel Programming 6 January 12th 04 07:30 PM


All times are GMT +1. The time now is 03:24 AM.

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

About Us

"It's about Microsoft Excel"