Defining a Range Using Elements From a Collection

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

Caution: this post is related to a previous post, but due to the previous post lacking all critical elements contributing to the conflict I am posting again with new material information, namely the collection component to the problem.

I am trying to define a range that incorporates variables taken from a collection as in the script below. I am thinking there may be conflict in the Range argument due to the fact that the variables used to define the ranges used in the Pearson arguments are being drawn from a collection. Could my Pearson arguments not make sense or be or an incorrect type?

Code:
Dim ws As WorksheetDim za As Variant
Dim zb As Variant
Dim zc As Variant
Dim zz As Variant
Dim xx As Variant
Dim ww As Variant
Dim zj As Variant
Dim zh As Variant
Dim zi As Variant
Dim yy As Variant


Dim col As New Collection
Dim col2 As New Collection


col.Add "b"
col.Add "c"
col.Add "D"
col.Add "E"
col.Add "F"
col.Add "G"
col.Add "h"
col.Add "i"
col.Add "j"
col.Add "k"
col.Add "l"
col.Add "m"
col.Add "n"
col.Add "o"
col.Add "P"
col.Add "Q"
col.Add "R"
col.Add "S"
col.Add "T"
col.Add "U"
col.Add "V"
col.Add "W"
col.Add "x"
col.Add "y"
col.Add "z"
col.Add "AA"
col.Add "AB"
col.Add "AC"
col.Add "AD"
col.Add "AE"
col.Add "AF"
col.Add "AG"
col.Add "AH"
col.Add "AI"
col.Add "AJ"
col.Add "AK"
col.Add "AL"
col.Add "AM"
col.Add "AN"
col.Add "AO"
col.Add "AP"
col.Add "AQ"
col.Add "AR"
col.Add 45
col.Add "AT"
col.Add "AU"
col.Add "AV"
col.Add "AW"
col.Add "AX"
col.Add "AY"
col.Add "AZ"
col.Add "BA"
col.Add "BB"
col.Add "BC"
col.Add "BD"
col.Add "BE"


col2.Add "BF"


For Each ws In Workbooks("COMM_PA.xls").Worksheets


zz = ActiveSheet.Name


yy = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row


For Each xx In col


za = xx


For Each ww In col2


zb = ww


With Workbooks("COMM_PA.xls").Worksheets(zz)


zh = Application.WorksheetFunction.Pearson(.Range(.Cells(2, zb), .Cells(yy, zb)), .Range(.Cells(2, za), .Cells(yy, za)))

Any ideas on troubleshooting this conflict would be much appreciated.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top