I can't insert the array values in the excel sheet

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to insert values into an excel table with the help of an array, it happens that when the program executes only the first value of the array is inserted in each specified range, how can I change this?


VBA Code:
Private Sub FillCells()

    Dim myarray_ac_before As Variant, marray_ac_after As Variant, marray_sphere_before As Variant, marray_sphere_after As Variant, marray_compensation_before As Variant, marray_compensation_after As Variant

    marray_ac_before = Array(MachineName, N_OT, Tec, Date_Today, hour, A_Grid_Orig, C_Grid_Orig, A2, A4, Xrel_90)
    marray_ac_after = Array(A_Grid_Orig_D, C_Grid_Orig_D, A2_D, A4_D, Xrel_90_D)
    marray_sphere_before = Array(P666, P709, P710, P713, A0, A_90, A90, Delta_A)
    marray_sphere_after = Array(P666r, P709r, P710r, P713r, A0r, A_90r, A90r, Delta)
    marray_compensation_before = Array(C0_A, C315_A, C270_A, C225_A, C180_A, C135_A, C90_A, C45_A, InitialSpread)
    marray_compensation_after = Array(C0, C315, C270, C225, C180, C135, C90, C45, FinalSpread)
    marray_spread = Array(InitialSpread, FinalSpread, Runnout)
    
    Workbooks("Corrections_Data.xlsm").Sheets("AC_Offset_Registers").Activate
    k_machine = Cells(Rows.Count, 2).End(xlUp).Offset(1).Row
    
    Range(Cells(k_machine, 2), Cells(k_machine, 11)) = Application.Transpose(marray_ac_before)
    Range(Cells(k_machine, 13), Cells(k_machine, 17)) = Application.Transpose(marray_ac_after)
    Range(Cells(k_machine, 19), Cells(k_machine, 26)) = Application.Transpose(marray_sphere_before)
    Range(Cells(k_machine, 28), Cells(k_machine, 35)) = Application.Transpose(marray_sphere_after)
    Range(Cells(k_machine, 37), Cells(k_machine, 45)) = Application.Transpose(marray_compensation_before)
    Range(Cells(k_machine, 47), Cells(k_machine, 55)) = Application.Transpose(marray_compensation_after)
    Range(Cells(k_machine, 57), Cells(k_machine, 59)) = Application.Transpose(marray_spread)
    
    Application.Run "Corrections_Data.xlsm! Text_In_Cells_Offset", k_machine

End Sub


help.JPG
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Don't transpose the arrays.
 
Upvote 0
Don't transpose the arrays.
Being honest I took reference from someone else's code, I don't know what the "transpose" does, could you tell me how I would have to put the code to make it work?
 
Upvote 0
I mean instead of this:

Code:
   Range(Cells(k_machine, 2), Cells(k_machine, 11)) = Application.Transpose(marray_ac_before)

just use this:

Code:
   Range(Cells(k_machine, 2), Cells(k_machine, 11)) = marray_ac_before

and similarly for the other lines.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top