+ Reply to Thread
Results 1 to 7 of 7

Storing items in an array

  1. #1
    Registered User
    Join Date
    12-07-2006
    Posts
    36

    Storing items in an array

    Hi.

    I'm trying to program a macro that will run down the first column of a worksheet, counting the number of product names it finds.
    The product names are the only items on the worksheet that are in a bold font, so I'm using this attribute to identify them.
    The macro moves down the rows by incrementing the variable 'rowNo'.
    It keeps a tally of the products in 'prodCount'.

    The problem I'm having is that I also want the macro to store all the names of the products it finds into a 1-dimensional array called 'prodList'.
    At the end of the macro the product count is displayed via a message box, and this seems to be working okay.
    But a second message box that is supposed to display the first and last items in the product list array doesn't show any names have been stored.

    Have I set up the array wrong?
    Or am I storing the product names incorrectly?
    Any help with this problem would be appreciated.

    Here is the macro code:


    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by iterature
    Hi.

    I'm trying to program a macro that will run down the first column of a worksheet, counting the number of product names it finds.
    The product names are the only items on the worksheet that are in a bold font, so I'm using this attribute to identify them.
    The macro moves down the rows by incrementing the variable 'rowNo'.
    It keeps a tally of the products in 'prodCount'.

    The problem I'm having is that I also want the macro to store all the names of the products it finds into a 1-dimensional array called 'prodList'.
    At the end of the macro the product count is displayed via a message box, and this seems to be working okay.
    But a second message box that is supposed to display the first and last items in the product list array doesn't show any names have been stored.
    Hi,

    Yes it does.

    Perhaps re-test on a small sample, then larger samples, to see where it errors for you.

    Also, the line For i = 1 To 25400 could use 1 to iLastRow if you mean to cover all entries in column A
    Set last row as
    iLastRow = ActiveSheet.Range("A65536").End(xlUp).Row

    Let me know how you go
    ---
    Si fractum non sit, noli id reficere.

  3. #3
    Registered User
    Join Date
    12-07-2006
    Posts
    36
    Many thanks for your help, Bryan.

    As you suggest, I will try to test it on a smaller sample.

  4. #4
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by iterature
    Many thanks for your help, Bryan.

    As you suggest, I will try to test it on a smaller sample.
    Hi,

    Just curious, how many rows do you have, and how many do you expect to find?

    also, simply do

    For i = 1 to 100

    to check it works (it did for me)

    then 1000, 10000 20000 etc

    Cheers
    ---

  5. #5
    Registered User
    Join Date
    12-07-2006
    Posts
    36
    Quote Originally Posted by Bryan Hessey
    Hi,

    Just curious, how many rows do you have, and how many do you expect to find?

    also, simply do

    For i = 1 to 100

    to check it works (it did for me)

    then 1000, 10000 20000 etc

    Cheers
    ---
    The sheet has about 25000 rows, so I set up the For loop to go just past the end.
    I think there should probably be around 3000 bold items in the sheet.

    I haven't had a chance to try a smaller set yet - hopefully I'll get some time to try it later.
    Thanks for your help.

  6. #6
    Registered User
    Join Date
    12-07-2006
    Posts
    36
    Bryan,

    I've just tried it for the first 100 rows and it didn't work, so I had another look at the worksheet.
    It turns out that the items I thought were in bold are in fact not in bold - they're just in an unusual font.

    So the macro should be working okay.
    It's been counting up blank cells which were set as bold for some reason (I don't know why.)

    As you can probably tell, I'm pretty much a beginner at this stuff - so sorry for my misunderstanding of the problem (my bad.)

    Thanks again for your help.

  7. #7
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by iterature
    Bryan,

    I've just tried it for the first 100 rows and it didn't work, so I had another look at the worksheet.
    It turns out that the items I thought were in bold are in fact not in bold - they're just in an unusual font.

    So the macro should be working okay.
    It's been counting up blank cells which were set as bold for some reason (I don't know why.)

    As you can probably tell, I'm pretty much a beginner at this stuff - so sorry for my misunderstanding of the problem (my bad.)

    Thanks again for your help.
    Hi, and no worry.

    If you have further problems with this just re-post.

    ---

+ 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