+ Reply to Thread
Results 1 to 8 of 8

Different results for ComboBox.RowSource property in BeforeUpdate Event

  1. #1
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Different results for ComboBox.RowSource property in BeforeUpdate Event

    Greetings,

    I have the following code in the beforeupdate event of combobox.

    Please Login or Register  to view this content.

    While debugging, I noticed that the line result for

    Please Login or Register  to view this content.
    is different from

    Please Login or Register  to view this content.
    The former is always one row less than the latter. Can someone please explain what could be the cause even though I have a WITH statement to identify the range?

    Many thanks
    Asha

    Last edited by asha3010; 09-28-2010 at 01:08 PM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Different results for ComboBox.RowSource property in BeforeUpdate Event

    Try this:
    Please Login or Register  to view this content.
    or better still, don't use the RowSource at all.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Different results for ComboBox.RowSource property in BeforeUpdate Event

    Hi Asha;

    I'm guessing that Range("test") is a dynamic range.

    When your code encounters "With Range("test")" it sets the range that will be used for all the "." statements following, and doesn't reevaluate Range("test") again.

    But when your code encounters
    Please Login or Register  to view this content.
    it reevaluates Range("test") again and it now contains one more row than when the macro started.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  4. #4
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Different results for ComboBox.RowSource property in BeforeUpdate Event

    Thanks very much to both for your prompt response.

    @romperstomper: You recommended not using Rowsource property. Would the other option be using the "Additem" method?

    @foxguy: Thanks for the clarification. You are correct - it is a dynamic range.

    I had encountered the 're-evaluate' issue when using the SET statement. I thought I could avoid it using the WITH statement but that doesn't seem to be the case.

    Is there any other way to get excel to re-evaluate the dynamic range or just that we have to very careful while dealing with dynamic ranges in VBA.

    Many thanks
    Asha

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Different results for ComboBox.RowSource property in BeforeUpdate Event

    Use Additem or List.

  6. #6
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Different results for ComboBox.RowSource property in BeforeUpdate Event

    Thanks romperstomper.
    Asha

  7. #7
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Different results for ComboBox.RowSource property in BeforeUpdate Event

    Quote Originally Posted by asha3010 View Post

    Is there any other way to get excel to re-evaluate the dynamic range or just that we have to very careful while dealing with dynamic ranges in VBA.
    I don't think there is any way to have a range dynamically reevaluated. VB will only evaluate the range when you tell it to.

  8. #8
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Different results for ComboBox.RowSource property in BeforeUpdate Event

    Ok, thanks foxguy.
    Asha

+ 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