Variables for many subroutines: code clean up
<p>I've been thinking and searching for quite a few hours for a solution, but couldn't come up with the answer to my basic problem (obviously hard for me):</p>

<p>So I have many subroutines:</p>

<pre><code>Sub OUTPUT()

Call CompañiasCubiertas
Call RangosDatos
Call EERR
Call Balance
Call Flujo
Call Indicadores
Call FormatoEERR
Call FormatoBalance
Call FormatoFlujo
Call FormatoIndicadores

End Sub
</code></pre>

<p>In each of this subs, I have many variables and workbooks declaration that are repeated:</p>

<pre><code>Dim y As Workbook
Dim x As Workbook

Dim rangoi As Integer
Dim rangof As Integer
Dim compañia As String
Dim oipf As Integer
Dim ogpf As Integer 
Dim ogp As Integer 
Dim Fechai As Long
Dim Fechaf As Long
Dim Fechaper1 As Long
Dim Fechaper2 As Long


Set y = Application.ActiveWorkbook
Set x = Application.Workbooks.Open("G:\Estudios\Biblioteca\Mercado Accionario Chileno\BBDD Oficial.xlsm")

compañia = y.Sheets("Información Financiera").Range("A3")

'Definir rangos para buscar los datos

Fechai = y.Sheets("Información Financiera").Range("C4").Value
Fechaf = y.Sheets("Información Financiera").Range("D4").Value
Fechaper1 = y.Sheets("Información Financiera").Range("C8").Value
Fechaper2 = y.Sheets("Información Financiera").Range("D8").Value
rangoi = Application.Match(Fechai, y.Sheets("Información Financiera").Range("E2:E300"), 0) + 1
rangof = Application.Match(Fechaf, y.Sheets("Información Financiera").Range("E2:E300"), 0) + 1
</code></pre>

<p>So, how can I avoid to declare all of this variables and workbooks in ALL subs.
I've been trying what I read in almost every site:</p>

<pre><code>Public rangoi As Integer
Public rangof As Integer
</code></pre>

<p>and so on.... But if I create these variables inside <code>OUTPUT()</code>, It throws an error, and Outside It won't be read when I start the macro.</p>

<p>I am missing something basic here.</p>

<p>I'm particularly interested in making the variable...</p>

<pre><code>Dim compañia As String
 compañia = y.Sheets("Información Financiera").Range("A3")
</code></pre>

<p>... usefull for all the subroutines, because I want to do a Loop over the variable <code>compañia</code> ( reseting it as an array of strings ) and put a <code>for</code> in the <code>OUTPUT</code> subroutine as:</p>

<pre><code> Sub OUTPUT()
    For i=1 To UBound(compañia)

Call subs1 ' subs1(compañia) , meaning the value of compañia changes the value of subroutines
Call subs2 ' subs2(compañia)
Call subs3 ' subs3(compañia)

Next i
End Sub
</code></pre>