View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Wesslan Wesslan is offline
external usenet poster
 
Posts: 27
Default Variables in Variables

On Feb 12, 10:13*am, Carlos wrote:
Hi,

I'm new to VBA programming and have been working on a generic input sheet
which will save details in different folders relevant to variables in a few
cells (questions via a userform completes these cells).

I've got most of the varibles to work when searching for the correct file
but I can't seem to get the below to work. Is this because it's a variale
itself and therefore not possible?

sectionfolder = Workbooks("KPI Advisor stat
sheet.xls").Worksheets("Stats").Range("C1") * * * * 'in this case Export
sectiontotalname = Workbooks("KPI Advisor stat
sheet.xls").Worksheets("Stats").Range("D1") * * * ' IN this case Export Total
advisor = Workbooks("KPI Advisor stat
sheet.xls").Worksheets("Stats").Range("E1") * * * * * * * ' In this case
Export 1
sectiontotalworksheet = Workbooks("KPI Advisor stat
sheet.xls").Worksheets("stats").Range("F1") ' In this case Total Export

Application.ScreenUpdating = False

' This one works fine.

Workbooks.Open Filename:="S:\Credit Management\Shared\KPI's\Section\" &
sectionfolder & "\Current\" & sectiontotalname & ".xls"

' but I can't get this variable to follow the correct path. I've tried with
and without the &'s and xls.

monthopen =
Workbooks(sectiontotalname).Worksheets(sectiontota lworksheet).Range("M1").V*alue

Any help would be much appricated.

Thanks
carl


Carl,

I am no expert. But my guess is that you have to check how you have
defined the variables. For intance are both "sectiontotalname" and
"sectiontotalworksheet" defined as strings? If they are it should
work.

If you want a workaround (probably get slaughtered by everyone in the
forum for this) I suggest you try this:

monthopen =
Workbooks("" & sectiontotalname).Worksheets("" &
sectiontotalworksheet).Range("M1").V*alue

Lastly are have you defined the monthopen in a proper way for the
value (I am guessing it is a number so integer, or long should work).

i.e "Dim monthopen as integer"

If you copy out the error message that appears maybe I could be more
helpful.

Best regards,