![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 1
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
|
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 (My other life: http://damonostrander.com ) |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|