+ Reply to Thread
Results 1 to 5 of 5

How to use an Array

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134

    Question How to use an Array

    I was wondering if anyone knew how i would use an array for this code.

    The array would hold the strings ( "Status",.....)
    The "C" representing columns 1 To 19

    Idealy i would use one line to say for cells 1 to C, Execute the array.


     For C = 1 To 19
                        .Cells(1, C).Value = "Status"
                        .Cells(1, C).Value = "Test Type"
                        .Cells(1, C).Value = "User ID"
                        .Cells(1, C).Value = "Probe"
                        .Cells(1, C).Value = "Date"
                        .Cells(1, C).Value = "Text Note"
                        .Cells(1, C).Value = "Faliure Reason"
                        .Cells(1, C).Value = "Serial Number"
                        .Cells(1, C).Value = "Start Time"
                        .Cells(1, C).Value = "Rig Number"
                        .Cells(1, C).Value = "First Test"
                        .Cells(1, C).Value = "Production"
                        .Cells(1, C).Value = "Verification"
                        .Cells(1, C).Value = "Test Aborted"
                        .Cells(1, C).Value = "Test Incomplete"
                        .Cells(1, C).Value = "Test Failed"
                        .Cells(1, C).Value = "Test Passed"
                        .Cells(1, C).Value = "FTF"
                        .Cells(1, C).Value = "FTP"
                    Next C
                End With

    .Cells(1, C).Value = HeadingCol()
    Somehting like this would be my guess.

    Does anyone know the solution.

    Thanx George

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    Perhaps you mean something along the lines of:

    Dim str_headers
    str_headers = Array("Status", "Test Type", "User ID", "Probe", "Date", "Text Note", "Failure Reason", "Serial Number", "Start Time", "Rig Number", _
                        "First Test", "Production", "Verification", "Test Aborted", "Test Incomplete", "Test Failed", "Test Passed", "FTF", "FTP")
    With ActiveSheet
        .Cells(1, 1).Resize(1, UBound(str_headers)).Value = str_headers
    End With
    I would happily concede I'm most certainly not the best when it comes to working with Array's so someone else is likely to come up with a better approach than the above.

  3. #3
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134
    That is great it works so long as i add an End to the last string which means it stops 1 before the end.


       Dim str_headers
                            str_headers = Array("Status", "Test Type", "User ID", "Probe", "Date", "Text Note", "Failure Reason", "Serial Number", "Start Time", "Rig Number", "First Test", "Production", "Verification", "Test Aborted", "Test Incomplete", "Test Failed", "Test Passed", "FTF", "FTP", "end")
    
                        .Cells(1, 1).Resize(1, UBound(str_headers)).Value = str_headers
    Maybe it starts at 0 apposed to 1

    George

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    Yes, my bad, I did say I wasn't very good... you can use Option Base to force to start at 1 but instead of having End in your array use the original but with:

     .Cells(1, 1).Resize(1, 1 + UBound(str_headers)).Value = str_headers

  5. #5
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134
    Yeah that works fine now, I have only done this a few months so am probably pritty bad.

    Thanx for the help

    George

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1