using Array in vba

zeus

New Member
Joined
Dec 31, 2003
Messages
44
Hello,
Hopefully the answer to my question will be a quick one.
I have a macro that tries to find account 600000, if it finds it, the code needs to insert 12 rows above the account number row and I need to enter Jan-Dec in those 12 freshly inserted rows (column B). My code is working fine up to the point where I'm trying to insert Jan-Dec in the 12 new rows. I'm using the code below and it seems to work fine if I wanted the 12 months entered horizontally, but I can't get it to work when trying to populate the cells vertically, I get "Jan" in all 12 months!

code that works to display the months horizontally:
Cells.Find(what:="600000").Offset(-12, 0).Resize(1, 12).Value = Array("Jan", "Feb", "Mar", "Apr"...,"Dec")

I thought I could flip the Resize parameters around and it would display the months vertically...but I got 12 Jan's instead
code that doesn' work to display the months vertically:
Cells.Find(what:="600000").Offset(-12, 0).Resize(12, 1).Value = Array("Jan", "Feb", "Mar", "Apr"...,"Dec")

Is is possible to use =Array(...) to have the results displayed vertically? Or maybe I need to write my code another way?

I appreciate any insight you might be able to provide.
Thanks kindly
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try:
... = Application.Transpose(Array("Jan", "Feb", "Mar", "Apr"...,"Dec"))
 
Upvote 0
Ahhhhh, thank you Peter, this works perfectly. I had pulled out most of my hair already! Such a simple thing when you see the answer.

have a great day!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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