Dear guys and girls,
I have an Array to be populated with intArray (an integer variable set earlier) number of values from a column in a sheet called "Reference". The source column varies, but is always the column holding the cell, "strRefCell".
I would like to avoid having to unhide the Reference sheet (necessary for the code below to work), select the sheet, locate the first cell to copy from (two cells above strRefCell) before finally using a For/Next loop to populate the values of the array as I suspect there might be an easier way.
Is there a way I can perform this in a more streamlined way?
To give you an idea of what I had in mind, my (fawlty) code attempt was:
arrWithForm = Worksheets("Reference").Range((strRefCell.offset(-2,0))
strRefCell.offset((intArray-2),0))
Here's what is doing the job. I have other more complex Subs I'd like to apply a successful alternative logic to (including copying values from the array into the sheet), otherwise I wouldn't ask for your help for such a small thing!
Sub RefToArray()
.....Dim n As Integer
.....Worksheets("Reference").Visible = True 'WON'T WORK WITHOUT THIS...
.....Worksheets("Reference").Select
.....Range(strRefCell).Offset(-2, 0).Select 'finds first cell to pull _
.....data from by using strRefCell (Row 4) and offsetting 2 rows up.
.....For n = 1 To (intArray + 2)
.......arrWithForm
= ActiveCell.Value
.......ActiveCell.Offset(1, 0).Select
.....Next
.....Worksheets("Reference").Visible = xlSheetHidden '...OR THIS
End Sub
Elsewhere:
.....Public arrWithForm() as Currency
.....Public strRefCell as String
.....Public intArray as Integer
Many thanks
I have an Array to be populated with intArray (an integer variable set earlier) number of values from a column in a sheet called "Reference". The source column varies, but is always the column holding the cell, "strRefCell".
I would like to avoid having to unhide the Reference sheet (necessary for the code below to work), select the sheet, locate the first cell to copy from (two cells above strRefCell) before finally using a For/Next loop to populate the values of the array as I suspect there might be an easier way.
Is there a way I can perform this in a more streamlined way?
To give you an idea of what I had in mind, my (fawlty) code attempt was:
arrWithForm = Worksheets("Reference").Range((strRefCell.offset(-2,0))
Here's what is doing the job. I have other more complex Subs I'd like to apply a successful alternative logic to (including copying values from the array into the sheet), otherwise I wouldn't ask for your help for such a small thing!
Sub RefToArray()
.....Dim n As Integer
.....Worksheets("Reference").Visible = True 'WON'T WORK WITHOUT THIS...
.....Worksheets("Reference").Select
.....Range(strRefCell).Offset(-2, 0).Select 'finds first cell to pull _
.....data from by using strRefCell (Row 4) and offsetting 2 rows up.
.....For n = 1 To (intArray + 2)
.......arrWithForm
.......ActiveCell.Offset(1, 0).Select
.....Next
.....Worksheets("Reference").Visible = xlSheetHidden '...OR THIS
End Sub
Elsewhere:
.....Public arrWithForm() as Currency
.....Public strRefCell as String
.....Public intArray as Integer
Many thanks