How do i make a variable to a parameter

Lino

Active Member
Joined
Feb 27, 2002
Messages
429
I am looping through a file with a for each statement and then in the for loop statement i am comparing the value of the cell with tickers to the for each loop ticker value and if the same i assign the value of the shares for the ticker to the totshares variable with the parameter of the Ticker in question.

then later on down the code when i reference TotShare(ThisTicker) I will be able to see how many shares for each specific ticker.

How do I set this up so TotShares will take a parameter.

Thanks Lino

For Each NewTicker In Range("C1:C" & Range("C65536").End(xlUp).Row)
ThisTicker = NewTicker.Value

For i = 1 To FinalRow
If Cells(i, 3) = ThisTicker And (Action = "B" Or Action = "BL") Then
TotShares(ThisTicker) = TotShares + Cells(i, 2)
End If
Next i
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Would a formula solution work?
Book2
ABCDE
1B123EMC5697B
2BL456SUNW6696BL
3OTHER789IBM2577
4B1122IBM 
5BL1455IBM 
6OTHER1788EMC 
7B2121SUNW 
8BL2454EMC 
9OTHER2787SUNW 
10B3120EMC 
11BL3453XYZ3453
12OTHER3786EMC 
13B4119SUNW 
Sheet2


D1: =IF(COUNTIF($C$1:$C1,$C1)=1,SUMPRODUCT(--(ISNUMBER(MATCH($A$1:$A$13,$E$1:$E$2,0))),--($C$1:$C$13=$C1),$B$1:$B$13),"")
_________________
 
Upvote 0
VB it is, here we go:
SQL Test.xls
ABCD
1ActionValueTicker
2B123EMC
3BL456SUNW
4OTHER789IBM
5B1122IBM
6BL1455IBM
7OTHER1788EMC
8B2121SUNW
9BL2454EMC
10OTHER2787SUNW
11B3120EMC
12BL3453XYZ
13OTHER3786EMC
14B4119SUNW
Sheet1


Becomes:
SQL Test.xls
ABCD
1EMC5697
2IBM2577
3SUNW6696
4XYZ3453
Sheet2


With the help of:

Code:
Sub SumTicks()
Dim cn As Object, rs As Object
Dim clcMde As Long

clcMde = Application.Calculation
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Sheets(2).[a2:iv65536].ClearContents

Set cn = CreateObject("ADODB.Connection")

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
    ThisWorkbook.FullName & ";Extended Properties=Excel 8.0;"
    
Set rs = CreateObject("ADODB.Recordset")
With rs
    Set .ActiveConnection = cn
    .Source = "Select [Ticker], Sum([value]) From [Sheet1$a1:iv65536] " & _
        "Where [Action] = ""B"" or [Action] =""BL"" Group By [Ticker]"
    .Open , , 3, 3
    Sheets(2).[a1].CopyFromRecordset rs
    .Close
End With
cn.Close
Set rs = Nothing: Set cn = Nothing

Application.Calculation = clcMde
Application.ScreenUpdating = True

End Sub
 
Upvote 0
when trying to run the following code i get a error saying sub or function not defined ( I have marked the line look below)

How do i fix it?


Sub parse()

Dim TotShares(1 To 1000) ' Make this large enough
Dim Tickers(1 To 1000)

SRow = 1
FinalRow = Range("A65536").End(xlUp).Row


MyNumber = 0
For Each NewTicker In Range("C1:C" & Range("C65536").End(xlUp).Row)
ThisTicker = NewTicker.Value

MyNumber = MyNumber + 1
************Complains with the line below
Ticker(MyNumber) = ThisTicker
TotShares(MyNumber) = 0

For i = 1 To FinalRow

Set Action = Cells(i, 1)


If Cells(i, 3) = ThisTicker And (Action = "B" Or Action = "BL") Then
TotShares(MyNumber) = TotShares(MyNumber) + Cells(i, 2)
End If
Next i
Next NewTicker

End Sub
 
Upvote 0
Replace this --

Ticker(MyNumber) = ThisTicker

with this --

Tickers(MyNumber) = ThisTicker
 
Upvote 0
at the same time i don't understand your insistence on not using loops...perhaps u are better at this than i am which is most likely the case so explain your reluctance about loops.
 
Upvote 0
This is fair enough. Please might be nice, I am trying to help you at no cost to you...

In any case, if your data set is large, the loop will perform much more slowly, probably will on a small data set as well. Especially when using cell properties. E.g.,

http://www.mrexcel.com/board2/viewtopic.php?t=84948&start=4

Did you solve the double loop (slower yet)?

Did the sql not yield what you wanted?
 
Upvote 0
i did not solve the double loop...side tracked with other projects...

I would very much like it if i moved away from cell properties and moved into more of what you speak of...but you know when u know how to do something one way and when you need to pull a script together in a short time you just stick with what you know...sort of like saying i'll put in comments after writing or declaring variables when it is all done...

and it also comes down to time...unfortunately only still 24 hrs in a day.

Hopefully I can find time to learn what it is you speak of.

Thanks for the help.

Lino
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,571
Members
449,173
Latest member
Kon123

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