Determine if part of a multi-line cell has been deleted using VBA

Laavista

Board Regular
Joined
Aug 27, 2009
Messages
79
I'm using Excel 2007. Using VBA, I need to determine if part of a multi-line cell has been deleted.

Example

Contents of cell A1 before user clicks on the cell
-comment 1
-status 2
-status 3


User deletes second line
-comment 1
-status 3

I need to determine if a 'line' has been deleted. I thought I could count the number of characters in the cell before and after, but can't get the number of characters in the cell before they make the changes.

Any suggestions?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I'm using Excel 2007. Using VBA, I need to determine if part of a multi-line cell has been deleted.

Example

Contents of cell A1 before user clicks on the cell
-comment 1
-status 2
-status 3


User deletes second line
-comment 1
-status 3

I need to determine if a 'line' has been deleted. I thought I could count the number of characters in the cell before and after, but can't get the number of characters in the cell before they make the changes.

Any suggestions?

Put this in the sheet code:

Dim oldval1, oldval

Private Sub Worksheet_Change(ByVal Target As Range)
oldval1 = Target.Value
MsgBox "oldvalue: " & oldval & vbCrLf & "newval: " & oldval1
End Sub




Private Sub Worksheet_SelectionChange(ByVal Target As Range)
oldval = Target.Value
End Sub
 
Upvote 0
The approach you've suggested (counting cells) will tell you if there are any changes in the string but not necessarily whether you've lost a line. You can combine the following with Kevin.Philips approach to see whether there are less lines (if that's what you need):

Code:
NoOfLines = Len(Range("A1")) - Len(Replace(Range("A1"), vbLf, "")) + 1
[code]
 
Upvote 0
Put this in the sheet code:

Dim oldval1, oldval

Private Sub Worksheet_Change(ByVal Target As Range)
oldval1 = Target.Value
MsgBox "oldvalue: " & oldval & vbCrLf & "newval: " & oldval1
End Sub




Private Sub Worksheet_SelectionChange(ByVal Target As Range)
oldval = Target.Value
End Sub

I will try this and let you know. THANKS!!
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top