View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Kevin H. Stecyk[_2_] Kevin H. Stecyk[_2_] is offline
external usenet poster
 
Posts: 43
Default Reading a Range to an Array

Hi,

I am doing something wrong in trying to read a range from a spreadsheet into
an array. Below are the relevant portions of my code. I have omitted the
extraneous stuff.

Sub UpdateSheet()
'\Three string names
Dim sSpreadShtNameRng As String '\Range Name1
Dim sPwdNameRng As String '\Range Name2
Dim sWriteResPwdNameRng As String '\Range Name3

Dim vaSpreadShtName As Variant
Dim vaPwd As Variant
Dim vaWriteResPwd As Variant

Dim iCounter As Integer

sHiddenFileName = "Hidden"

'\ 3 range name are on the sheet "Hidden"
'\ All ranges are local..but I tried global
'\too and it failed.

sSpreadShtNameRng = "xrnSpreadShtNameCC" '\Range Name1
sPwdNameRng = "xrnPwd1CC" ' \Range Name2
sWriteResPwdNameRng = "xrnPwd2CC" '\Range Name3


'\Activate Hidden sheet.
Worksheets(sHiddenFileName).Activate

'\ I think below is where I am going wrong...

vaSpreadShtName = Range(sSpreadShtNameRng).Value
vaPwd = Range(sPwdNameRng).Value
vaWriteResPwd = Range(sPwdNameRng).Value

'\ Below I get iCounter=1, but the next step yields an error message
'\ Run-time error: 9, subscript out of range.

For iCounter = 1 To 5 Step 1
Debug.Print iCounter
Debug.Print vaSpreadShtName(iCounter)
Debug.Print vaPwd(iCounter)
Debug.Print vaWriteResPwd(iCounter)
Next iCounter

End Sub


Can you see my error(s)? And if so, can you please shed some light on this
matter for me.

Thank you.

Regards,
Kevin