Help with an array

nuggett

Board Regular
Joined
Apr 26, 2006
Messages
78
Can anyone tell me why this doesn't work. I have checked the locals window which confirms dteTme has 1 to 358 elements.

New to arrays and need some help.

Cheers

Mark

Code:
Sub testzone()
    Dim DteTme()
    Dim RoundedDteTme(1 To 358)
    
    DteTme = Range("E3", Range("E3").End(xlDown))
    
    x = 1
    
    For Each element In DteTme
        RoundedDteTme(x) = DteTme(x)
        x = x + 1
    Next element

End Sub

I currently get a subscript out of range error on the following line:

Code:
RoundedDteTme(x) = DteTme(x)
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi mark

Could you tell me exactly what you are trying to do please.

Dave
 
Upvote 0
DteTme is a 2-dimensional array.
Code:
Sub testzone()
    Dim DteTme()
    Dim RoundedDteTme(1 To 358)
    
    DteTme = Range("E3", Range("E3").End(xlDown))
    
    x = 1
    
    For Each element In DteTme
        RoundedDteTme(x) = DteTme(x, 1)
        x = x + 1
    Next element

End Sub
 
Upvote 0
Thanks Norie
How can I assign it as a single dimensional array, I only want it to take values from one column in the sheet.
 
Upvote 0
If you want a single dimension array use Application.Transpose.
Code:
    DteTme = Application.Transpose(Range("E3", Range("E3").End(xlDown)).Value)
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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