Hi,
I am working on a long macro. I'm not really good with VBA but so far, I'm impressed by what I've done (of course, with the help of the macro recorder and a lot of "google" code researches).
I would like to know if it's possible when you write your sub in VBA to refer to a cell for changing a string or a value in your code.
I don't want to always touch my VBA code to switch little values or names.
I would prefer to change them in cells in a worksheet named "info".
2 differents exemples I'd like to improve.
could I set up something like:
Dim filename as string
Dim upperbound as single
filename = Worksheets("info").Cells(1, 1).Value
upperbound = Worksheets("info").Cells(1, 2).Value
First, I would like to use "filename" to replace the word "Results" in the code line below.
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\bob\Desktop\Results " & Format(Date, "dd-mmm-yy") & ".xls", FileFormat _
:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Second, in a part of a vba code starting the Solver, I would like to use "upperbound" to replace the value "0.15" in the code below
SolverOk SetCell:="$U$13", MaxMinVal:=1, ValueOf:=0, ByChange:="$U$5:$U$7", _
Engine:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$U$5:$U$7", Relation:=1, FormulaText:="0"
SolverAdd CellRef:="$U$5:$U$7", Relation:=3, FormulaText:="0.15"
I know I cannot only switch "results" by "filename " and "0.15" by "upperbound"... but I guess there is a simple way to do it.
I found stuff using the "&" but I don't know how to apply this correctly.
thanks your help
I am working on a long macro. I'm not really good with VBA but so far, I'm impressed by what I've done (of course, with the help of the macro recorder and a lot of "google" code researches).
I would like to know if it's possible when you write your sub in VBA to refer to a cell for changing a string or a value in your code.
I don't want to always touch my VBA code to switch little values or names.
I would prefer to change them in cells in a worksheet named "info".
2 differents exemples I'd like to improve.
could I set up something like:
Dim filename as string
Dim upperbound as single
filename = Worksheets("info").Cells(1, 1).Value
upperbound = Worksheets("info").Cells(1, 2).Value
First, I would like to use "filename" to replace the word "Results" in the code line below.
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\bob\Desktop\Results " & Format(Date, "dd-mmm-yy") & ".xls", FileFormat _
:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Second, in a part of a vba code starting the Solver, I would like to use "upperbound" to replace the value "0.15" in the code below
SolverOk SetCell:="$U$13", MaxMinVal:=1, ValueOf:=0, ByChange:="$U$5:$U$7", _
Engine:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$U$5:$U$7", Relation:=1, FormulaText:="0"
SolverAdd CellRef:="$U$5:$U$7", Relation:=3, FormulaText:="0.15"
I know I cannot only switch "results" by "filename " and "0.15" by "upperbound"... but I guess there is a simple way to do it.
I found stuff using the "&" but I don't know how to apply this correctly.
thanks your help