VBA: How do I use a Variable Name in a formula
I want to use the Bin2Hex method with variable names. Two columns of binary data are in columns C and D in worksheet 2 (W2). The formula will be in a cell a1 on worksheet 1 (W1). The Excel formula is simple:
=(W2!C1 & W2!D1 for the data in row 1. But how do I do this with variables replacing C1 and D1? I've spent hours attempting to sort this.
Here is one method I tried but I get an error
[VBA]sheets("W2").activate
var1=range("C2")
var2=range("D2")
sheets("W1").activate
Range("a1").Formula = "=bin2hex(W1!"var1 "& W2! "var2")"[/VBA]
The other issue is in var1 and var2, I will have to assign these dynamicaly to different cells. Not quite sure of the format here?
This can't be that hard.
Variable names in formulas using VBA
Yes, there's the rub. I agree if I knew the cells this is trivial. I have simplified my question from the real application which will have users adding or subtracting rows from sowrksheet 2 (W2) therefore I don't know the cell addresses.
Bin2Hex and variable name
This appears to work but I don't understand the syntax of the Rangefor Formula statement
.FormulaR1C1 = "=BIN2Hex(" & oneCell.Address(False, True, xlR1C1, True, .Cells(1, 1)) & _
"&" & twoCell.Address(False, True, xlR1C1, True, .Cells(1, 1)) & ")"
Bin2hex with variables as arguments
Thanks again. Two more questions.
1. Why the double ampersand & "&" ?
2. Where is all of this hidden knowledge documented?
thanks for your expertise - it means a lot to me.
Bin2Hex with variable argument
OK, I got it. Also found some additional documentation. But have run into more problems.
I'll submit a new thread as this one is getting too long.