Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Write values based on a array to a certain cell across worksheets Excel VBA

I am trying to assign a list of names to a certain cell (E4) across all worksheets. This is what I have so far. I am not sure the proper way of assigning values from a array across all worksheets. The error message says the subscription is out of range. But I can’t find a solution to fix it. Thank you

Sub test()

Dim ws1 As Worksheet
Dim i As as Long
Dim myArray As Variant
Set ws1 = Worksheets("Sheet9")
myArray = Worksheets("data").Range("range")
 With ws
    For Each ws In ActiveWorkbook.Worksheets
        ws.Range(i, 4) = myArray(i)
    Next
  
 End With


End Sub

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

myArray is a one-based, 2D array.

Sub test()
    Dim myArray As Variant
    myArray = ActiveWorkbook.Worksheets("data").Range("range")

    Dim i As Long
    For i = LBound(myArray, 1) to UBound(myArray, 1)
         ActiveWorkbook.Worksheets(i).Range("E4").Value = myArray(i, 1)
    Next
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading