PC Review


Reply
Thread Tools Rate Thread

Array basics!

 
 
John
Guest
Posts: n/a
 
      1st May 2010
Well I am stuuck - I am Sure someone out there can unstick me...

I have a legcy text file report that I am developing a VBA module to
translate into an Excel spreadsheet, which then will be used for several
things, one of which is to import into the database. There are 91 fields
used in the report. I would like to create an array and then assign the
names of the fields to the array so I can use a counter to populate the
spreadsheet with the field names. Something like:

Dim fldNames(91) as String

fldNames = "ActId","Act_Title", "Budget", "Actual", ... etc.

I would then like to use the array to populate an excell spreadsheet

For i = 1 to 91
xlsht.Cells(1, i).value = fldName(i)
next i

Question is how do I easily populate fldNames(91) with the string values for
the field names?


--
Thanks in advance!
**John**
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      1st May 2010
Dim fldNames As Variant

fldNames = Array("ActId","Act_Title", "Budget", "Actual", ... etc.)
For i = 1 to 91
xlsht.Cells(1, i).value = fldName(i-1)
next i

(note that the array will start at 0, not 1)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"John" <(E-Mail Removed)> wrote in message
news:95D2CBE4-EFFA-4C8C-B56D-(E-Mail Removed)...
> Well I am stuuck - I am Sure someone out there can unstick me...
>
> I have a legcy text file report that I am developing a VBA module to
> translate into an Excel spreadsheet, which then will be used for several
> things, one of which is to import into the database. There are 91 fields
> used in the report. I would like to create an array and then assign the
> names of the fields to the array so I can use a counter to populate the
> spreadsheet with the field names. Something like:
>
> Dim fldNames(91) as String
>
> fldNames = "ActId","Act_Title", "Budget", "Actual", ... etc.
>
> I would then like to use the array to populate an excell spreadsheet
>
> For i = 1 to 91
> xlsht.Cells(1, i).value = fldName(i)
> next i
>
> Question is how do I easily populate fldNames(91) with the string values
> for
> the field names?
>
>
> --
> Thanks in advance!
> **John**


 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      2nd May 2010
An alternative is to write one long string and then you the Split
function to push the contents in to an arra

Dim strFieldList
Dim vNamesArray as Variant
Dim i as Long

strFieldList = "ActID;Act_Title;Budget;Actual;...;LastItem"
vNamesArray = Split(strFieldList,";")
For i = LBound(vNamesArray) to UBound(vNamesArray)
xlsht.Cells(1, i+1).value = vNamesArray(i)
next i

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

On 4/30/10 10:01 PM, Douglas J. Steele wrote:
> Dim fldNames As Variant
>
> fldNames = Array("ActId","Act_Title", "Budget", "Actual", ... etc.)
> For i = 1 to 91
> xlsht.Cells(1, i).value = fldName(i-1)
> next i
>
> (note that the array will start at 0, not 1)
>

 
Reply With Quote
 
John
Guest
Posts: n/a
 
      3rd May 2010
Doug! You are a life (finger) saver! I was thinking I would have to type
all that stuff out.

I have another question about "Type... End Type"... I'll post it in a new
thread so we don't mix topics.

Thanks again.
--
Thanks in advance!
**John**


"Douglas J. Steele" wrote:

> Dim fldNames As Variant
>
> fldNames = Array("ActId","Act_Title", "Budget", "Actual", ... etc.)
> For i = 1 to 91
> xlsht.Cells(1, i).value = fldName(i-1)
> next i
>
> (note that the array will start at 0, not 1)
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
>
> "John" <(E-Mail Removed)> wrote in message
> news:95D2CBE4-EFFA-4C8C-B56D-(E-Mail Removed)...
> > Well I am stuuck - I am Sure someone out there can unstick me...
> >
> > I have a legcy text file report that I am developing a VBA module to
> > translate into an Excel spreadsheet, which then will be used for several
> > things, one of which is to import into the database. There are 91 fields
> > used in the report. I would like to create an array and then assign the
> > names of the fields to the array so I can use a counter to populate the
> > spreadsheet with the field names. Something like:
> >
> > Dim fldNames(91) as String
> >
> > fldNames = "ActId","Act_Title", "Budget", "Actual", ... etc.
> >
> > I would then like to use the array to populate an excell spreadsheet
> >
> > For i = 1 to 91
> > xlsht.Cells(1, i).value = fldName(i)
> > next i
> >
> > Question is how do I easily populate fldNames(91) with the string values
> > for
> > the field names?
> >
> >
> > --
> > Thanks in advance!
> > **John**

>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Basics nany Microsoft Outlook VBA Programming 2 23rd Sep 2008 09:12 AM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
meaning of : IF(Switch; Average(array A, array B); array A) =?Utf-8?B?RFhBVA==?= Microsoft Excel Worksheet Functions 1 24th Oct 2006 06:11 PM
Basics of VBA and SQL Jonas Microsoft Access VBA Modules 3 7th Mar 2006 05:02 PM
VPN Basics Not Me Windows XP Work Remotely 0 15th Oct 2004 01:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:30 PM.