+ Reply to Thread
Results 1 to 19 of 19

block if without end if

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    block if without end if

    Hi,

    I'm trying to fill a cell with information but i'm getting the "block if error". any help would be gratefully received.

    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.EnableEvents = False
        If Range("O9").Value = YES Then
            Range("X9").Value = "[email protected]"
    
    
     If Range("O9").Value = NO Then
            Range("X9").Value = ""
            Else
       
            Range("X9").ClearContents
        End If
        Application.EnableEvents = True
        
    End Sub

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: block if without end if

    You don't need the second If at all:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.EnableEvents = False
        If Range("O9").Value = "YES" Then
            Range("X9").Value = "[email protected]"
        Else
            Range("X9").ClearContents
        End If
        Application.EnableEvents = True
    End Sub
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,455

    Re: block if without end if

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    http://www.mrexcel.com/forum/excel-q...-if-error.html
    http://www.excelguru.ca/forums/showt...ed=1#post27447

  4. #4
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    OK, no problem

    When I choose, the No from pull down menu, the cell is still populated, is there any way i can remove the .hotmail when i select no?

  5. #5
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: block if without end if

    ClearContents and setting Value property to "" (vbNullString) yield exactly the same result

  6. #6
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    thats how i understood it, cant understand why selecting no will not clear the box, would it have anything to do with my data validation of yes, no and clear ?

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: block if without end if

    upload a workbook

  8. #8
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    Here it is: just a data validation pull down menu
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    ok gimme two mins

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: block if without end if

    Hi,

    Your validation cell is Y5 rather than O9.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  11. #11
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    Just one more thing. Is it possible to add the extra email to the merged cell above?. I've tried but the added email replaces those already populated by the box. I can get the code to produce two emails but it would reduce errors if I could send only one?

  12. #12
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    aww yeah sorry, i cut and paste and missed an update. Thanks very much for that.

  13. #13
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: block if without end if

    How would you need it to be added- separated by a comma/semicolon/line feed?

  14. #14
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    yeah, I've used semi-colon to separate 4 emails as Outlook does.

  15. #15
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: block if without end if

    You need only test if the cell is empty first

    If Range("X9").value = vbnullstring then
        Range("X9").value = "email address"
    Else
        Range("X9").value = Range("X9").value & "; " & "email address"
    End If

  16. #16
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    wonderful, thank you ever so much

  17. #17
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    aw sorry its still replaces the e-mail in the merged cells rather than adds to it. Have i pasted the code correctly?

    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.EnableEvents = False
        If Range("Y5").Value = "YES" Then
            Range("X3").Value = "[email protected];[email protected];[email protected];[email protected]"
            
            If Range("X3").Value = vbNullString Then
        Range("X3").Value = "email address"
    Else
        Range("X3").Value = Range("X3").Value & "; " & "email address"
    End If
        Else
            Range("X3").ClearContents
        End If
        Application.EnableEvents = True
    End Sub
    I suspect that I will have to unmerge the cells in order to get it to work?

  18. #18
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: block if without end if

    I believe we are talking at cross-purposes. If it is always the same set of email addresses then you can use the code you had before. If not, can you clarify exactly what you meant?

    There is little point testing for an empty cell on the line after you populate that cell, and I was not recommending you actually put the words "email address" in to the cell- that was to be replaced with the relevant actual address.

  19. #19
    Forum Contributor
    Join Date
    07-05-2016
    Location
    cardiff
    MS-Off Ver
    2010
    Posts
    787

    Re: block if without end if

    Sorry mate, it's been a long day, i'll re-evaluate. I'm out of office till morning. Again, thank you for your guidance and wisdom

+ 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. Block If without End If
    By Oilfield in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-14-2015, 02:51 PM
  2. New kid on the block
    By firsttimer in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 05-20-2015, 05:26 PM
  3. New boy on the block
    By Firepoint in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 06-04-2014, 12:51 PM
  4. Replies: 5
    Last Post: 10-09-2012, 10:44 AM
  5. End if without If Block
    By cbh35711 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2012, 04:32 PM
  6. Replies: 2
    Last Post: 06-22-2010, 07:55 AM
  7. help!! block if without end if.
    By spinkung in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2006, 11:12 PM

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