Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: getting data out of merged cells

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    hey... I'm making a vb script that beeps and gives a msgbox if a user types in more than 25 characters in a string. The following code works when I try it with 1 cell, but I get a data mismatch error when I try to check the contents of a merged cell. Is there something besides excel.range.value I should be using?

    Thanks in advance,

    -ROb

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim ThisCell As String
    If Target.Column = 2 And Target.Row = 15 Then
    ThisCell = Mid(Target.Value, 26, 1)
    If ThisCell <> "" Then
    Beep
    foo = MsgBox("Please enter no more than 26 characters", vbOKOnly)
    Target.Value = "enter text here"
    End If
    End If
    End Sub


  2. #2
    MrExcel MVP Damon Ostrander's Avatar
    Join Date
    Feb 2002
    Location
    Denver, Colorado USA
    Posts
    4,239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi vbnewbie,

    The problem is that a merged cell is actually a range containing more than one cell, and you can't access the Value property of a range containing more than one cell. I believe in your case the problem will go away if you change all your references to Target.Value to Target.Cells(1).Value, which just yields the first cell in the range (which is where the displayed cell contents reside).
    Keep Excelling.

    Damon

    VBAexpert Excel Consulting
    LinkedIn Profile http://www.linkedin.com/pub/damon-ostrander/7/79/a93
    AllExperts Profile http://www.allexperts.com/ep/1059-30...-Ostrander.htm

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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