Consulting

Results 1 to 4 of 4

Thread: Make VBA Cell a Formula

  1. #1

    Make VBA Cell a Formula

    I have some code that finds the value based upon a counter, such as:

    Cells(10, 10) = Cells(CounterA, ColumnA)

    ...Lets say CounterA=1

    I want Cells(10,10) to actually be "=A1", rather than whatever value was contained when it was run. Any ideas? For some reason, I thought I did this before, but can not find the code to do it.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA] Dim CounterA As Long, ColumnA As String
    ColumnA = "A"
    CounterA = 1
    Cells(10, 10).Formula = "=" & ColumnA & CounterA[/VBA]

  3. #3
    Is there a more "direct" way? What can one do if ColumnA is not a constant value (but rather obtained from a loop).

    Perhaps I gave an oversimplified example. That said, I may still be able to get this to do what I want "as is".

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Try:
    [VBA]Sub example()
    Const CounterA As Long = 1
    Const ColumnA As Long = 1

    Cells(10, 10).Formula = "=" & Cells(CounterA, ColumnA).Address(0, 0, , -1)
    End Sub[/VBA]

Posting Permissions

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