Excel: Populating a range with a formula

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CoreyReynolds
    New Member
    • Nov 2009
    • 29

    Excel: Populating a range with a formula

    Hey all,

    Here's the culprit:

    Code:
    Sub PopulateRange(Cell_Range As Range)
    
    Dim v
    Dim i As Long
    Dim j As Long
    Application.ScreenUpdating = False
    ReDim v(1 To Cell_Range.Rows.Count, 1 To Cell_Range.Columns.Count)
    For i = 1 To Cell_Range.Rows.Count
    For j = 1 To Cell_Range.Columns.Count
    
    'only takes last 8 chars of data cell
    v(i, j) = "=RIGHT(G" & i & ", 8)"
    'fills the cells in Z column a calculation that calculates based off the information in the cell that is filled by the above line
    v(i + 1, j) = "=ExtractNumber(Z" & i & ", , True)"
    Next j
    Next i
    Cell_Range.Value = v
    Application.ScreenUpdating = True
    End Sub
    What should happen:
    I pass in the range and it fills that range with two calculation I have (already made it and verified it words "ExtractNumber" ) which calculates some stuff to the left of it brilliantly and everyone at my office loves me.

    What happens:
    Doesn't do anything all all... but when error testing it's popping up my MsgBox with exactly what I want to have placed in the range but doesn't populate it and everyone at my office hates me.
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    dear,

    The v is an array !
    If you want the values of that array, you have to define them

    Cell_Range.Valu e = v (??,??)

    I have tried to sumulate you problem : see ataachment



    br,
    Attached Files

    Comment

    Working...