Consulting

Results 1 to 9 of 9

Thread: Solved: Merged Cells Null Value

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location

    Solved: Merged Cells Null Value

    Hello,

    I am somewhat of a beginner and am really struggling with this code. I read alot of forums where everyone says don't use merged cells but I'm afraid I need to. I can not seem to get the code to recognise a blank value in the merged cell. As soon as I unmerge, it works fine. Is there a work around for this or something I am missing?

    This is just a simplified example of where I am coming from. Merged cells would be C4:E4
    ___________________________________________________

    [VBA] Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$C$4" Then
    If Range("C4") = "" Then
    MsgBox ("Empty")
    Else
    MsgBox ("Value")
    End If

    End If
    End Sub[/VBA]
    ___________________________________________________

    Any help would be greatly appreciated.

    Andrew

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Andrew, Welcome to Vbax. Are you sure that merged cells are the option? The advice coming through from the experts is that we should stay away from merged cells, because it causes problems. Why isn't it possible to simply select the cells and use "centre across selection"?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What problem are you getting. If I clear C4, it shows the Empty message. Isn't that what you want?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location
    Quote Originally Posted by Aussiebear
    Andrew, Welcome to Vbax. Are you sure that merged cells are the option? The advice coming through from the experts is that we should stay away from merged cells, because it causes problems. Why isn't it possible to simply select the cells and use "centre across selection"?
    Thanks Aussiebear. Regretfully, The way the spreadsheet is laid out, the merge is needed. Am i correct in saying, if I use "centre across selection", then they can only clear the value by selecting C4, where as with a merged cell, it doesn't matter where in the range they select?

    Quote Originally Posted by xld
    What problem are you getting. If I clear C4, it shows the Empty message. Isn't that what you want?
    Did you merge cells C4:E4?

    I have attached and simple example fo my error.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What is the error? It does everything that you put in the listr, which is exactly what you want isn't it?

    Which step does other than what you expect?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by roo
    Thanks Aussiebear. Regretfully, The way the spreadsheet is laid out, the merge is needed. Am i correct in saying, if I use "centre across selection", then they can only clear the value by selecting C4, where as with a merged cell, it doesn't matter where in the range they select?.
    In merged cells they can only select the first, so if you use Center ACroos, you add a select event so that selecting any of those cells changes to selecting the first.

    But ... as I said, what is the problem?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location
    Thanks for you quick replies.

    If you use back space and enter it will msg Empty but if you use del or clear contents, nothing happens.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    See, it helps if you tell us the full story

    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells(1, 1).Address = "$C$4" Then

    If Range("C4") = "" Then
    MsgBox ("Empty")
    Else
    MsgBox ("Value")
    End If

    End If

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location
    I can't believe it was so simple

    Sry, I just realised that backspace works.

    Thanks again for you help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •