0

This should be fairly straightforward. But for some reason I'm getting blank cells instead of the values from the array being passed into the cells.

redim rFin (2,1)
rfin (1,1) = "Bla1"
rfin (2,1) = "Bla2"

oSht1 = activesheet
lRow = 10

With oSht1
    .Range(.Cells(lRow1 + 1, 6), .Cells(lRow1 + 2, 6)) = rFin
End With

EDIT: Also tried with rFin having values from 0 to 1 instead of 1 to 2.

1
  • ReDim rFin (1 To 2, 1 To 1) Commented Aug 1, 2016 at 1:53

3 Answers 3

3

This works for me:

Option Base 1

Sub Main()
    ReDim rfin(2, 1)
    rfin(1, 1) = "Bla1"
    rfin(2, 1) = "Bla2"

    Set oSht1 = ActiveSheet
    lRow = 10

    With oSht1
        .Range(.Cells(lRow + 1, 6), .Cells(lRow + 2, 6)) = rfin
    End With
End Sub

The important thing is the Option Base 1 because without it arrays start at 0. Or this would work:

'default of Option Base 0

Sub Main()
    ReDim rfin(2, 1)
    rfin(0, 0) = "Bla1"
    rfin(1, 0) = "Bla2"

    Set oSht1 = ActiveSheet
    lRow = 10

    With oSht1
        .Range(.Cells(lRow + 1, 6), .Cells(lRow + 2, 6)) = rfin
    End With
End Sub
Sign up to request clarification or add additional context in comments.

3 Comments

oh... I didn't know that! I just found a workaround. I'll post it as an answer (although my workaround is not as elegant as your more effective solution)
btw, do you know if base 1 can be used with a single variant? (Instead of affecting all variants through the subs.)
Well, idk, using redim rFin(1 to 2,1) does not work for me (I end up with blank cells). My work around (using an empty range to make the variant match the range's format) allows me to use a single variant of this format (thus not having to change the variants and loops I had already set up).
0

I found a workaround: using an empty range to make the variant match the range's format, which allows me to use a single variant of this format (thus not having to change the variants and loops I had already set up).

oSht1 = activesheet
lRow = 10

With oSht1
    rFin = .Range(.Cells(lRow1 + 1, 6), .Cells(lRow1 + 2, 6))
End With

    rfin(1, 1) = "Bla1"
    rfin(2, 1) = "Bla2"

With oSht1
    .Range(.Cells(lRow1 + 1, 6), .Cells(lRow1 + 2, 6)) = rFin
End With

Not an elegant solution, but it does work. Just use an empty range.

1 Comment

That's a good solution to avoid having to worry about the base of the array.
0
oSht1.Cells(lRow1 + 1, 6).Resize(2) = [{"Bla1";"Bla2"}]

or even shorter

[F11:F12] = [{"Bla1";"Bla2"}]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.