I have a fairly large “master” spreadsheet and I am trying to create a *.csv file (as a separate file) that captures data from one column of the “Master” spreadsheet. Each row in the *.csv file will be a concatenation of some constants and some variable (all separated by commas of course), but underlying the arrangement in the master spreadsheet are two indices I will refer to as “A” and “B”. There are 6 “A” values (1 thru 6) and within each of these there are 53 “B” values (1 thru 53) for a total of 318 combinations. I was hoping to loop using two nested “for next” loops for each of these nested array indices, filling the array with data from the master worksheet as it progressed. Next, I would activate the new *.csv spreadsheet & increment to each row, creating each concatenated row text value from corresponding array and constant data items(row qty = “A” X “B”). My question is how do I set up a two dimensional array or would I be better off just switching the focus back & forth between the two workbooks as I constructed each row’s text (kind of like using the master spreadsheet’s rows and columns as my data container rather than loading an array)?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
VBA Excel Multi Dimensional Array
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » VBA Excel Multi Dimensional Array
- This topic has 7 replies, 2 voices, and was last updated 15 years, 7 months ago.
AuthorTopicWSJHWilkinson
AskWoody LoungerOctober 12, 2009 at 1:03 pm #463127Viewing 0 reply threadsAuthorReplies-
Don Wells
AskWoody LoungerOctober 12, 2009 at 1:30 pm #1181007I have a fairly large “master” spreadsheet and I am trying to create a *.csv file (as a separate file) that captures data from one column of the “Master” spreadsheet. Each row in the *.csv file will be a concatenation of some constants and some variable (all separated by commas of course), but underlying the arrangement in the master spreadsheet are two indices I will refer to as “A” and “B”. There are 6 “A” values (1 thru 6) and within each of these there are 53 “B” values (1 thru 53) for a total of 318 combinations. I was hoping to loop using two nested “for next” loops for each of these nested array indices, filling the array with data from the master worksheet as it progressed. Next, I would activate the new *.csv spreadsheet & increment to each row, creating each concatenated row text value from corresponding array and constant data items(row qty = “A” X “B”). My question is how do I set up a two dimensional array or would I be better off just switching the focus back & forth between the two workbooks as I constructed each row’s text (kind of like using the master spreadsheet’s rows and columns as my data container rather than loading an array)?
What I believe you have described is a worksheet with a 6 cell by 53 cell table. Why not save that sheet as a csv file?
-
WSJHWilkinson
AskWoody LoungerOctober 12, 2009 at 4:12 pm #1181050What I believe you have described is a worksheet with a 6 cell by 53 cell table. Why not save that sheet as a csv file?
Don,
Thanks for the input. Actually it’s a little more involved than that. The structure of the input to the problem is header info (constants on first couple of rows, various columns) and then two columns of index data followed bay a column of descriptor data selected by the user with a resulting format something like:
A1 B1 Description1
A1 B2 Description2
…
A1 B53 Description 53
A2 B1 Description 54
A2 B2 Description 55
…
A2 B53 Description 106
A3 B1 Description 107
etc…And the csv output must look like this (it is an import file to a program I have no control over, so no flexibility there):
(Constant 1), (Constant 2), (Constant 3), (A1 value), (B1 Value), (Description1), (Constant 4), (Constant 5)
(Constant 1), (Constant 2), (Constant 3), (A1 value), (B2 Value), (Description2), (Constant 4), (Constant 5)
…
(Constant 1), (Constant 2), (Constant 3), (A1 value), (B53 Value), (Description53), (Constant 4), (Constant 5)
(Constant 1), (Constant 2), (Constant 3), (A2 value), (B1 Value), (Description54), (Constant 4), (Constant 5)
(Constant 1), (Constant 2), (Constant 3), (A2 value), (B2 Value), (Description55), (Constant 4), (Constant 5)
…
(Constant 1), (Constant 2), (Constant 3), (A2 value), (B53 Value), (Description106), (Constant 4), (Constant 5)
(Constant 1), (Constant 2), (Constant 3), (A3 value), (B1 Value), (Description107), (Constant 4), (Constant 5)
etc…But possibly I could just copy / paste vertical columns of each variable data type to form this structure (I will have to do this in segments as there are interruptions (unwanted rows) in the data every 53 rows. I could then just transfer the constant data into the appropriate columns and fill to the bottom of the active row range. Not the direction I first started in, but I’ll give it a try.
-
Don Wells
AskWoody LoungerOctober 12, 2009 at 5:05 pm #1181056But possibly I could just copy / paste vertical columns of each variable data type to form this structure (I will have to do this in segments as there are interruptions (unwanted rows) in the data every 53 rows. I could then just transfer the constant data into the appropriate columns and fill to the bottom of the active row range. Not the direction I first started in, but I’ll give it a try.
I would be inclined to add a new sheet that returns the table in the order you want for the csv file. This need only be done once and will be ready to be saved at any time.
Can you post a copy of the file with sensitive data removed?
-
Don Wells
AskWoody LoungerOctober 12, 2009 at 8:26 pm #1181068The attached file provides a working example of what I believe you need. It contains the following code:
Code:Option Explicit Public Sub Create_CSV() 'Set the following constants to the required string Const C1 = "Constant 1" Const C2 = "Constant 2" Const C3 = "Constant 3" Const C4 = "Constant 4" Const C5 = "Constant 5" 'Set the following constants to the appropriate path; filename; and sheetname Const Pathspec = "C:Trash" 'Path for the csv file Const Filespec = "MyFile.csv" 'csv filename Const Sheetspec = "Sheet2" 'Name of the sourrce sheet Dim CtrA As Long ' The A index Dim CtrB As Long ' The B index With Sheets(Sheetspec) Open Pathspec & Filespec For Output As #1 For CtrA = 1 To 6 For CtrB = 1 To 53 Write #1, "(" & C1 & ")", "(" & C2 & ")", "(" & C3 & ")", _ "(" & .Range("A" & CtrA) & ")", _ "(" & .Range("B" & CtrB) & ")", _ "(" & .Range("C" & CtrB) & ")", _ "(" & C4 & ")", "(" & C5 & ")" Next CtrB Next CtrA Close #1 End With End Sub
H.T.H.
-
WSJHWilkinson
AskWoody LoungerOctober 12, 2009 at 8:49 pm #1181069Mr Wells,
Just got home to see your post. Thank you so much; that is incredibly efficient code. You have shown me some new techniques that I was totally unaware of & need to digest. My input code is a little different than your example, but I believe I can adjust to accommodate.
Here is one last twist for you; A couple of the constants (Constant 4 & 5) are really not constants, but must be selected from a list on the “master spreadsheet” and selecting the correct one (interpretation) is actually visual (hard to explain). have you ever seen a VBA/macro technique that halts the code execution and allows the user to navigate the “master” worksheet (in this case), select a cell containing the correct input value, and then continue code execution; using the value of the cell selected?
-
Don Wells
AskWoody LoungerOctober 13, 2009 at 10:59 am #1181120Mr Wells,
Just got home to see your post. Thank you so much; that is incredibly efficient code. You have shown me some new techniques that I was totally unaware of & need to digest. My input code is a little different than your example, but I believe I can adjust to accommodate.
Here is one last twist for you; A couple of the constants (Constant 4 & 5) are really not constants, but must be selected from a list on the “master spreadsheet” and selecting the correct one (interpretation) is actually visual (hard to explain). have you ever seen a VBA/macro technique that halts the code execution and allows the user to navigate the “master” worksheet (in this case), select a cell containing the correct input value, and then continue code execution; using the value of the cell selected?
Apologies; the file which I provided lost the form and its code. I will re-post with an updated version this evening. Sorry, but I must go now.
-
Don Wells
AskWoody LoungerOctober 13, 2009 at 12:13 pm #1181135Mr Wells,
Just got home to see your post. Thank you so much; that is incredibly efficient code. You have shown me some new techniques that I was totally unaware of & need to digest. My input code is a little different than your example, but I believe I can adjust to accommodate.
Here is one last twist for you; A couple of the constants (Constant 4 & 5) are really not constants, but must be selected from a list on the “master spreadsheet” and selecting the correct one (interpretation) is actually visual (hard to explain). have you ever seen a VBA/macro technique that halts the code execution and allows the user to navigate the “master” worksheet (in this case), select a cell containing the correct input value, and then continue code execution; using the value of the cell selected?
The attached has four named ranges; two with the lists of constants, and two with the selection results. I have also added a form with some code.
I recommend stepping through the code to gain an understanding.
Note a similar post was deleted as the file did not contain the form.
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Best Courses to Study in Dubai with High Job Prospects (Awaiting moderation)
by
SonaliSharmaBR
10 minutes ago -
Small desktops
by
Susan Bradley
1 hour, 13 minutes ago -
Totally disable Bitlocker
by
CWBillow
4 hours, 31 minutes ago -
Totally disable Bitlocker
by
CWBillow
6 hours, 10 minutes ago -
Windows 11 ad from Campaign Manager in Windows 10 (Awaiting moderation)
by
Jim McKenna
9 hours, 40 minutes ago -
Phishers extract Millions from HMRC accounts..
by
Microfix
18 hours, 19 minutes ago -
Windows 10 22H2 Update today (5 June) says up-to-date but last was 2025-04
by
Alan_uk
20 hours, 11 minutes ago -
Thoughts on Malwarebytes Scam Guard for Mobile?
by
opti1
23 hours, 19 minutes ago -
Mystical Desktop
by
CWBillow
23 hours, 33 minutes ago -
Meta and Yandex secretly tracked billions of Android users
by
Alex5723
4 hours, 51 minutes ago -
MS-DEFCON 2: Do you need that update?
by
Susan Bradley
13 hours, 44 minutes ago -
CD/DVD drive is no longer recognized
by
WSCape Sand
1 day, 14 hours ago -
Windows 11 24H2 Default Apps stuck on Edge and Adobe Photoshop
by
MikeBravo
1 day, 17 hours ago -
North Face and Cartier customer data stolen in cyber attacks
by
Alex5723
1 day, 15 hours ago -
What is wrong with simple approach?
by
WSSpoke36
1 day, 8 hours ago -
Microsoft-Backed Builder.ai Set for Bankruptcy After Cash Seized
by
Alex5723
2 days, 3 hours ago -
Location, location, location
by
Susan Bradley
17 hours, 32 minutes ago -
Cannot get a task to run a restore point
by
CWBillow
2 days, 4 hours ago -
Frustrating search behavior with Outlook
by
MrJimPhelps
1 day, 19 hours ago -
June 2025 Office non-Security Updates
by
PKCano
2 days, 15 hours ago -
Secure Boot Update Fails after KB5058405 Installed
by
SteveIT
17 hours, 52 minutes ago -
Firefox Red Panda Fun Stuff
by
Lars220
2 days, 15 hours ago -
How start headers and page numbers on page 3?
by
Davidhs
3 days, 1 hour ago -
Attack on LexisNexis Risk Solutions exposes data on 300k +
by
Nibbled To Death By Ducks
2 days, 4 hours ago -
Windows 11 Insider Preview build 26200.5622 released to DEV
by
joep517
3 days, 10 hours ago -
Windows 11 Insider Preview build 26120.4230 (24H2) released to BETA
by
joep517
3 days, 10 hours ago -
MS Excel 2019 Now Prompts to Back Up With OneDrive
by
lmacri
3 days ago -
Firefox 139
by
Charlie
2 days, 16 hours ago -
Who knows what?
by
Will Fastie
1 day, 18 hours ago -
My top ten underappreciated features in Office
by
Peter Deegan
3 days, 11 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.