Results 1 to 9 of 9

Thread: VBA: How do I use a Variable Name in a formula

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    16
    Location

    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.
    Last edited by Bob Phillips; 01-02-2012 at 04:53 AM. Reason: Added VBA tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •