Using Parameters in Visual Basic

L

lj

Hi, I'm creating a VB script and I've named a particular cell using
the code

Cobrand = Range("F10").Text

However, I'm trying to select Cobrand in a subsequent line of code,
and I want to be able to use Cobrand in the code below instead of F10

Range("F10").select

But when I try to use the following statement it doesn't work, any
suggestions???

Range(Cobrand).Select
 
M

Michael Gill

Hi,

The value of cobrand in your last command is whatever the text was in cell
F10. Instead of setting cobrand = range("F10").text set it to cobrand =
"F10".

This will allow your Range(Cobrand).Select statement to work.

Michael
 
G

George Nicholson

Cobrand = Range("F10").Text
assigns the *characters inside* cell F10 to Cobrand, not the address "F10".
Try:
Cobrand = Range("F10").Address

Cobrand will then equal the characters "$F$10" and
Range(Cobrand).Select
should work

Alternatively, you could also:
Dim Cobrand as Range
Set Cobrand = Range("F10")
Cobrand.Select

HTH,
 
Top