arrays

ONIWE

New Member
Joined
Jun 29, 2010
Messages
25
Guys Help!!!!!!!!



i'm learning arrays and each time i copy an array code into the code sheet and execute, nothing happens. Can someone please tell em what i'm doing wrong.

this is an example:


<CODE>Sub FillArray() Dim curExpense(364) As Currency Dim intI As Integer For intI = 0 to 364 curExpense(intI) = 20 NextEnd Sub</CODE></PRE>
<CODE></CODE> </PRE>
<CODE>I'm sure I'm supposed to see some changes in my spreadsheet.</CODE></PRE>
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,446
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Guys Help!!!!!!!!



i'm learning arrays and each time i copy an array code into the code sheet and execute, nothing happens. Can someone please tell em what i'm doing wrong.

this is an example:


<code>Sub FillArray() Dim curExpense(364) As Currency Dim intI As Integer For intI = 0 to 364 curExpense(intI) = 20 NextEnd Sub</code>
<code></code>
<code>I'm sure I'm supposed to see some changes in my spreadsheet.</code>
Your array as you've dimensioned it has 364 elements with indicies starting at 0 and running through 363. So, your for -next statement should begin with
For intI = 0 to 363
Once you've fixed that you need to add some code to transfer the array elements to your spreadsheet. As it stands, the array is filled, but there are no further instructions which would cause your spreadsheet to change.
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Your array as you've dimensioned it has 364 elements with indicies starting at 0 and running through 363.

Hi Joe

The array as dimensioned has by default 365 elements with indicies starting at 0 and running through 364.

One could change the default to base 1 but then the array would have 364 elements with indices 1-364.
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi ONIWE

I don't see anything wrong with your code. But it does nothing.

You fill the array and then you do nothing with it.
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,446
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi Joe

The array as dimensioned has by default 365 elements with indicies starting at 0 and running through 364.

One could change the default to base 1 but then the array would have 364 elements with indices 1-364.
Bad arithmetic! Thanks for setting me straight PGC.
 

ONIWE

New Member
Joined
Jun 29, 2010
Messages
25
Hi ONIWE

I don't see anything wrong with your code. But it does nothing.

You fill the array and then you do nothing with it.


That is exactly my point. How do I make use of the code. I got that code from the MS Excel help ....see below:

To set the value of an individual element, you specify the element's index. The following example assigns an initial value of 20 to each element in the array.

Sub FillArray()
Dim curExpense(364) As Currency
Dim intI As Integer
For intI = 0 to 364
curExpense(intI) = 20
Next
End Sub



if its not meant to do anything can someone please send me a sample one and two dimensional array that translates to something in the spreadsheet. Thanks guys.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,325
Messages
5,658,169
Members
418,430
Latest member
Chlwls808

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
Top