Closed Thread
Results 1 to 6 of 6

Ubound and Lbound

  1. #1
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Ubound and Lbound

    Hi guys,

    I was trying to do write a code that reads the 10th column of the row of the activecell and return the country i set in my array "arrcountry". It returns the first value and would not loop through the remaining. Am i doing something wrong here? Thanks.

    Dim i As Integer

    arrCountry(0, 0) = "USD"
    arrCountry(0, 1) = "United State"

    arrCountry(1, 0) = "SEK"
    arrCountry(1, 1) = "Sweden"

    For i = LBound(arrCountry, 1) To UBound(arrCountry, 1)
    Set Country = Cells(ActiveCell.row, 10)
    If Country = arrCountry(i, 0) Then
    ActiveCell = arrCountry(i, 1)
    ActiveCell.Offset(1, 0).Select
    End If

    Next
    Last edited by hommer; 09-21-2010 at 11:44 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Ubound and Lbound problem

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Ubound and Lbound

    Thanks guys.

    Marvin P - Sure, i will tag the codes. I noticed that after I posted the thread and I have put "i" as stated, it works fine until it hits a currency that is not declared in arrcountry and it will not look further. for example, it will stop at HKD below and will not populate further even the currency is declared in the array. is there a work around? am i missing an else if?

    USD United State
    SEK Sweden
    HKD
    USD
    SEK
    Richard - I have declared arrCountry and vlookup is possible but this is only a part of my code so would prefer to incorporate it rather then having it in the spreadsheet. Thanks.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Ubound and Lbound

    Hi,

    OK, Understood. But don't forget that you could still use this same technique but control it with a macro. i.e. have the macro temporarily add the VLOOKUP() formula and then copy and paste special values. This would avoid a VBA loop which generally slows things down and be much quicker since it uses a very efficient Excel function rather than slower VBA code.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    09-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Ubound and Lbound

    Thanks Richard, will try to write it in VBA loop first and try your method next time. thanks.
    Last edited by hommer; 09-21-2010 at 11:47 AM.

  6. #6
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Smile Re: Ubound and Lbound

    Hi hommer,
    Please find the attached file. Hope this will help you to solve your problem.
    Please find the below snapshot of the code I have used in this attached file.

    Please Login or Register  to view this content.
    Regards,
    Daksh
    Attached Files Attached Files
    Last edited by daksh1981; 09-21-2010 at 11:59 AM. Reason: Forgot to attaché file..
    I am still a learner.

Closed Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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