Results 1 to 15 of 15

Thread: Assign Formula Result to variable

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Ok, I wanted to ask another question but did not want to load up the front page with multiple questions from myself.

    What I want to do, is Step through 10 cells (B3:K3) and store the String Value of each Cell into an array. Immediatley after storing a value, I would like to output the String 3 cells below the originals in Row B. (basically as a check, and just so I understand the process)

    Here is my code. I am getting an error 450.

    [VBA]

    Sub Macro1()

    Dim StockName(10) As String

    For i = 1 To 10

    StockName(i) = Worksheets("Main").Range.Cells(3, i + 2).Value

    Worksheets("Main").Cells(6, i + 2).Value = StockName(i)

    Next

    End Sub

    [\VBA]

    Thanks again for all of your help.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    The end code tag for vba is /vba.

    Two methods: When using arrays to range, you sometimes need a WorksheetFunction.Transpose(a) or WorksheetFunction.Transpose(WorksheetFunction.Transpose(a)) depending on the matrix orientation.
    [vba]
    Sub test1()
    Worksheets("Main").Range("B3:K3").Copy Worksheets("Main").Range("B6:K6")
    Application.CutCopyMode = False
    End Sub

    Sub test2()
    Dim a() As Variant
    a() = Worksheets("Main").Range("B3:K3").Value
    Worksheets("Main").Range("B6:K6").Value = a()
    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
  •