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, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
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, 6 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
-
Notice on termination of services of LG Mobile Phone Software Updates
by
Alex5723
5 hours, 45 minutes ago -
Update your Apple Devices Wormable Zero-Click Remote Code Execution in AirPlay..
by
Alex5723
1 hour, 47 minutes ago -
Amazon denies it had plans to be clear about consumer tariff costs
by
Alex5723
8 hours, 11 minutes ago -
Return of the brain dead FF sidebar
by
EricB
1 hour, 4 minutes ago -
windows settings managed by your organization
by
WSDavidO61
2 hours, 53 minutes ago -
Securing Laptop for Trustee Administrattor
by
PeachesP
3 hours, 6 minutes ago -
The local account tax
by
Susan Bradley
21 minutes ago -
Recall is back with KB5055627(OS Build 26100.3915) Preview
by
Alex5723
14 hours, 47 minutes ago -
Digital TV Antenna Recommendation
by
Win7and10
7 hours, 20 minutes ago -
Server 2019 Domain Controllers broken by updates
by
MP Support
1 day, 2 hours ago -
Google won’t remove 3rd party cookies in Chrome as promised
by
Alex5723
1 day, 4 hours ago -
Microsoft Manager Says macOS Is Better Than Windows 11
by
Alex5723
1 day, 7 hours ago -
Outlook (NEW) Getting really Pushy
by
RetiredGeek
9 hours, 57 minutes ago -
Steps to take before updating to 24H2
by
Susan Bradley
46 minutes ago -
Which Web browser is the most secure for 2025?
by
B. Livingston
14 hours, 23 minutes ago -
Replacing Skype
by
Peter Deegan
2 hours, 56 minutes ago -
FileOptimizer — Over 90 tools working together to squish your files
by
Deanna McElveen
1 day, 1 hour ago -
Excel Macro — ask for filename to be saved
by
nhsj
38 minutes ago -
Trying to backup Win 10 computer to iCloud
by
SheltieMom
2 hours, 43 minutes ago -
Windows 11 Insider Preview build 26200.5570 released to DEV
by
joep517
3 days, 7 hours ago -
Windows 11 Insider Preview build 26120.3941 (24H2) released to BETA
by
joep517
3 days, 9 hours ago -
Windows 11 Insider Preview Build 22635.5305 (23H2) released to BETA
by
joep517
3 days, 9 hours ago -
No April cumulative update for Win 11 23H2?
by
Peobody
1 day, 21 hours ago -
AugLoop.All (TEST Augmentation Loop MSIT)
by
LarryK
3 days, 9 hours ago -
Boot Sequence for Dell Optiplex 7070 Tower
by
Serge Carniol
4 days ago -
OTT Upgrade Windows 11 to 24H2 on Unsupported Hardware
by
bbearren
4 days, 4 hours ago -
Inetpub can be tricked
by
Susan Bradley
2 days, 11 hours ago -
How merge Outlook 2016 .pst file w/into newly created Outlook 2024 install .pst?
by
Tex265
2 days, 22 hours ago -
FBI 2024 Internet Crime Report
by
Alex5723
4 days, 8 hours ago -
Perplexity CEO says its browser will track everything users do online
by
Alex5723
1 day, 17 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.