0

I have a script that pulls the first cell value of a table from a database and adds it 10 times. I want to write that list to excel.

Here's what I have so far:

sub x()
    Dim myArray As Variant
    Dim i As Variant

    myArray = Sheets("License Plate Number").Range("LP")
    myVariable = (Trim(Right(mp_start, 12)))

    For i = 0 To (ord_qty / 120) - 1

        Myarr = "MP" & myVariable + i
        myArray = Myarr

        'MsgBox Myarr
        Debug.Print Myarr

    Next i

end sub 

How can I write to a range using VBA?

1
  • If variables had sensible names, it would be much easier to understand the issue. Commented Dec 24, 2017 at 21:55

1 Answer 1

2

It's very simple. You just do it like this.

Range("A1:J1")=Myarr
Sign up to request clarification or add additional context in comments.

2 Comments

I did it just repeat the last number over
@TerranceMatthew That is because your myArray is not an array. It only contains the last value because you overwrite the entire contents of the variable on each loop iteration.

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.