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
-
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
5 hours, 43 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
6 hours, 50 minutes ago -
0Patch, where to begin
by
cassel23
52 minutes ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
20 hours, 28 minutes ago -
89 million Steam account details just got leaked,
by
Alex5723
8 hours, 13 minutes ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
1 day, 5 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
19 hours, 59 minutes ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
7 hours, 7 minutes ago -
Installer program can’t read my registry
by
Peobody
2 hours, 4 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
17 hours, 46 minutes ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
1 day, 1 hour ago -
False error message from eMClient
by
WSSebastian42
1 day, 16 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
2 days, 1 hour ago -
Office 2021 Perpetual for Mac
by
rebop2020
2 days, 2 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
23 hours, 2 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
2 days, 5 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
1 day, 6 hours ago -
Outdated Laptop
by
jdamkeene
2 days, 11 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
2 days, 16 hours ago -
Another big Microsoft layoff
by
Charlie
2 days, 16 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
13 hours, 50 minutes ago -
May 2025 updates are out
by
Susan Bradley
8 minutes ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
2 days, 22 hours ago -
Windows 11 Insider Preview build 26120.3964 (24H2) released to BETA
by
joep517
2 days, 22 hours ago -
Drivers suggested via Windows Update
by
Tex265
2 days, 22 hours ago -
Thunderbird release notes for 128 esr have disappeared
by
EricB
18 hours, 27 minutes ago -
CISA mutes own website, shifts routine cyber alerts to X, RSS, email
by
Nibbled To Death By Ducks
3 days, 5 hours ago -
Apple releases 18.5
by
Susan Bradley
2 days, 23 hours ago -
Fedora Linux 40 will go end of life for updates and support on 2025-05-13.
by
Alex5723
3 days, 6 hours ago -
How a new type of AI is helping police skirt facial recognition bans
by
Alex5723
3 days, 7 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.