+ Reply to Thread
Results 1 to 10 of 10

canīt get the else statment right

  1. #1
    Registered User
    Join Date
    05-14-2012
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    94

    canīt get the else statment right

    Hello again!
    I need help with "else"-statement, pls
    I have if statmenif there is a match, then the code writes to ws2
    If no , I want it to copy/paste to ws3. The else-code I wrote
    Please Login or Register  to view this content.
    fail to do this and writes nothing too ws3, but continues to write to ws2. In addition, it takes several seconds longer than before
    I enclose the workbook, the working macro is macro1 the not working is Private Sub CommandButton1_Click()Thanks in advance for your help
    Best regards
    Peter
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-14-2012
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: canīt get the else statment right

    I continue to work on a solution while waiting for help ;-)
    Wrote this macro, which shows what I want if the if / elseif statments are false
    Please Login or Register  to view this content.
    Unfortunatly the code donīt works:
    1) copys more then the referee
    2) it takes for ever and causes the excel to "not answer"
    //Peter

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: canīt get the else statment right

    Hi Peter,

    Hi Peter,

    I have another idea to do your work. See the attached and simply change the value in A5 and press enter. It will do an Advanced Filter of all your games showing what Refs need to show up. I've created an Dynamic Named Range of your Lista of all the games so you can add to that list and the filter will still work.

    See if this method of doing an Advanced Filter (using VBA) isn't a much easier solution.

    BTW - I too officiated many years ago and used Microsoft Access to keep track of games, places and referees.

    AdvFilter to get Referees to games.xlsm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    05-14-2012
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: canīt get the else statment right

    Hi Marvin and thanks for your answer.
    Iīm familliar with advanced filter. In tournamnets where Iīm in charge of referees I use advanced filter. But now Iīm doing this for a friend, and he wanted this in this way.

    In Sweden we get the games in Excel, thats why we work in Excel and not in Access.
    Why did you stiop officiating?

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: canīt get the else statment right

    Did you try to change the yellow cell on the second sheet and see how it filters for that ref's schedule?

    I officiated back in the late 1970's. I did both basketball and volleyball after teaching High School Math and Science during day. When I left teaching in 1983 to go into the software industry, I stopped officiating. When we moved to Seattle I helped the officials association with an Access db (in 1992) to do scheduling. They had two people who assigned games. One used Paradox (a windows database) and the other used an old DOS program written out of Utah. They never adopted my Access db for scheduling. I understand how many schools, churches, recreation places want officials of all different levels, pay and times. Excel seems like a great way to track this, especially if everyone uses it.
    Last edited by MarvinP; 08-04-2016 at 07:16 PM.

  6. #6
    Registered User
    Join Date
    05-14-2012
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: canīt get the else statment right

    Quote Originally Posted by MarvinP View Post
    Did you try to change the yellow cell on the second sheet and see how it filters for that ref's schedule?
    Yes, it works just fine :-)

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: canīt get the else statment right

    Your Private Sub CommandButton1_Click() works just fine if you take a minut to reread your Else statement.
    Every time no match is found you first clear the range on your sheet PO before copying. So in the end it's just the last no match found that is showing on PO.
    The solution is to move the clearing of sheet PO just beneath the clearing of sheet Blad2 and you're good to go.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Registered User
    Join Date
    05-14-2012
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: canīt get the else statment right

    thanks for your help

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: canīt get the else statment right

    You're welcome and thanks for the rep points.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: canīt get the else statment right

    Had some time left and added some code that a little faster in execution. Maybe better if list is bigger.
    To test fill in name and click first commandbutton. Msgbox will appear with execution time.
    Fill in same name and click second commandbutton. Again Msgbox will appear with execution time.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. need help with if statment
    By kyle1046 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-24-2014, 06:31 PM
  2. [SOLVED] IF Statment
    By mma3824 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2014, 12:27 PM
  3. Replies: 2
    Last Post: 06-06-2012, 10:59 PM
  4. Sum If Statment?
    By gballard in forum Excel General
    Replies: 4
    Last Post: 08-16-2011, 05:32 PM
  5. [SOLVED] IF statment within IF statment?
    By DaZombie in forum Excel General
    Replies: 2
    Last Post: 10-27-2010, 12:33 PM
  6. If statment
    By rhyan66 in forum Excel General
    Replies: 7
    Last Post: 10-16-2007, 09:32 AM
  7. [SOLVED] If statment
    By helpdesk genie in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-12-2005, 12:06 AM

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