arrays and variables

Status
Not open for further replies.

Lino

Active Member
Joined
Feb 27, 2002
Messages
429
Hello,

I don't know where to begin...

I have a file with stock tickers, action and shares in the following order:
action, shares, ticker

I want to aggregate the shares of any duplicate names with the same action.

I am trying to build this is a clean fashion as opposed to using "cells(i,1).value...

I want to build a For Each loop with an array as a variable.

Let's call it:

ticker[]

for i = 0 to FinalRow

ticker = cells(i,1).value what is the correct way to write this ticker is not vb.

cnt++

(I would like to replace cells...with an object, how can i do this. Currently a lot of my code is written in this manner and I would like to change it to variables instead)

let's continue.

So now i have

all of the different tickers in the variable ticker[]. then I want to loop through ticker[]:


for i = 0 to i < cnt
for j = 0 to j < cnt?
If ticker = ticker[j] then
shares[ticker] = cells(i,1) + cells(j,1) ' would prefer to use variables here but do not know how to set them up?

I don't know if this is complete but perhaps someone understands and can guide me.

Thanks,

Lino
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Looks like C... Three possibilities that make the most sense to me:

1) Pivot Table
2) Subtotals
3) SQL
 
Upvote 0
Sure. But I can't recommend it here.

And, don't confuse looping through a range object and working with properties as being the equivalent of working with a basic array, they're different animals.
 
Upvote 0
becuase of the board or because you don't know?

i don't understand the comment?
 
Upvote 0
It's quite straightforward, my comment is that double-loop through cells is a lot of overhead compared with alternatives.

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> test()
<SPAN style="color:darkblue">Dim</SPAN> i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, j <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> 20
    <SPAN style="color:darkblue">For</SPAN> j = 1 <SPAN style="color:darkblue">To</SPAN> 20
        MsgBox Cells(i, j).Value
    <SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,216,127
Messages
6,129,026
Members
449,482
Latest member
al mugheen

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