Search code examples
excelloopsgoogle-financevba

Excel VBA LOOP - Setting a variable's value by looping on another sheet's cells


Shortened the post. Complete code in the attached excel file.

Need help with correcting the looping code so that Variable gets value from a cell of another sheet repeats after certain process.

What's working correct already:: For a Single run::

  1. Currently, works only on 1 input (saved in ParameterSheet of workbook)
  2. Downloads data from gfinance
  3. Modifies data in consumable format (also adjusting time values)
  4. Exporting as csv
  5. Importing into another application

(Here's the excel file for reference)

Modifying the macro to work in a loop on a list of symbols in SymbolSheet. This list and count of list-items can keep changing.

Below is the code i have tried unsuccessfully :

'Starting Symbol loop --- Will DO STUFF till there are symbols in Symbol sheet

kal = SymbolSheet.Range("A1048576").End(xlUp).Row

For io = 1 To kal

ticker = Cells(io, 1).Value   ' fill ticker with cell value one by one

Symbolll = ticker & "-EQ"


'DO LOTS OF OTHER WORK

'Below code is coming from top where Ticker value is set

 Next io`

Solution

  • The answer has been provided by Scott. Given below:

    if you qualify the sheet in this line ticker = Cells(io, 1).Value it may help. For example, ticker = Sheets("Sheet1").Cells(io,1).Value where Sheet1 is the needed sheet name If the active sheet is any other than where you desire to get the ticker from, they way you have it written will not work. – Scott Holtzman