Avatar of Bob Stamm
Bob StammFlag for United States of America

asked on 

Load Array with Values on Excel worksheet

Looking to load array in Excel.  Will be assigning this code to a command button.

When selecting the command button all the values will be loaded into an array.

Sheet1
values D5 to ND5

I am just getting back into programming and need an model to get me going.  Thanks to anyone that can assist.
Microsoft ApplicationsMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Bob Stamm
Avatar of Norie
Norie

Quite straightforward really.
Dim arrData As Variant

    arrData = Sheets("Sheet1").Range("D5:ND5").Value ' fill array with data from N5:D5

Open in new window


Note the above code will produce a 2-dimensional array with the dimensions 1 to 1, 1 to 365, i.e. 1 row and 365 columns, if you like.
Avatar of Bob Stamm
Bob Stamm
Flag of United States of America image

ASKER

Thank you...that has me going.  I tosses in a msgbox to make sure I was getting the data loaded.  

thanks again and for the article too.
Avatar of Bob Stamm
Bob Stamm
Flag of United States of America image

ASKER

I now want to place my data on the "Print Calendar" worksheet.  The fill data array captured all the data for 365 days (works great).  I just want to place the first 31 days of data on the "Print Calendar" worksheet.  I assuming I need some type of loop or is there a more direct statement?  

Dim arrData As Variant

    arrData = Sheets("Calendar").Range("D5:ND5").Value ' fill array with data from D5:ND5

'This statement I wrote places the same value in each cell (I need help here).  
    Sheets("Print Calendar").Range("B55:AF55").Value = arrData(1, 2) ' Place calendar data for January
   
End Sub
Avatar of Norie
Norie

Try this.
    Sheets("Print Calendar").Range("B55").Resize(,31).Value = arrYear

Open in new window

Note, I've used Resize(,31) to expand the destination range for the data by 31 columns.
Avatar of Bob Stamm
Bob Stamm
Flag of United States of America image

ASKER

Starting to get there.  If I need to grab from 32 to 60 out of arrData how is that done?  This would be for my month of February.

Dim arrData As Variant
    arrData = Sheets("Calendar").Range("D5:ND5").Value ' fill array with data from D5:ND5

    Sheets("Print Calendar").Range("B55").Resize(,31).Value = arrData ' January Data
    Sheets("Print Calendar").Range("B56").....???                                       ' February Data
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bob Stamm
Bob Stamm
Flag of United States of America image

ASKER

This worked great.  Thank you for your help.
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo