Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Delete key casue a litte trouble

Hi all,

in change event, I can use trim(target.value) ="" to tell a user is erasing
a cell content until the Delete was pressed. How can I handle it?

Clara
--
thank you so much for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Delete key casue a litte trouble

why would you think using the delete key would not pass that test?

Do you mean the user had deleted multiple cells?

If target.count 1 then exit sub

at the start of your routine or figure out how you want to handle when
Target includes more than one cell.


--
Regards,
Tom Ogilvy


"clara" wrote:

Hi all,

in change event, I can use trim(target.value) ="" to tell a user is erasing
a cell content until the Delete was pressed. How can I handle it?

Clara
--
thank you so much for your help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Delete key casue a litte trouble

hi Tom,

I have a merged cell and using with a data validation. I use the following
function to check whether the cell's content is empty:

Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
If Trim(Previous) < "" And Trim(target.Value) = "" Then IsErasingCell =
True
End Function

previous is the value of the cell before change. I test with Spacebar,
Backspace and the empty value in data validation, they all work well, but
when I press Delete key, i got error message: Type mismatch. why?

Clara



thank you so much for your help


"Tom Ogilvy" wrote:

why would you think using the delete key would not pass that test?

Do you mean the user had deleted multiple cells?

If target.count 1 then exit sub

at the start of your routine or figure out how you want to handle when
Target includes more than one cell.


--
Regards,
Tom Ogilvy


"clara" wrote:

Hi all,

in change event, I can use trim(target.value) ="" to tell a user is erasing
a cell content until the Delete was pressed. How can I handle it?

Clara
--
thank you so much for your help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete key casue a litte trouble

Mergecells are a pain.

If you change put something into a merged cell, then the single cell is passed
to the event.

If you clear the merge area, then the whole mergearea is passed to the event.

Do yourself a big favor and stop using merged cells <vbg.

Maybe you can pick something out of this:

Option Explicit
Private Sub Worksheet_Change(ByVal target As Range)

Dim RealCellCount As Long
Dim myCell As Range
Dim FirstCell As Range

RealCellCount = 0
Set FirstCell = Nothing
For Each myCell In target.Cells
If myCell.MergeCells Then
If myCell.MergeArea.Cells(1).Address = myCell.Address Then
RealCellCount = RealCellCount + 1
If FirstCell Is Nothing Then
Set FirstCell = myCell
End If
End If
Else
RealCellCount = RealCellCount + 1
If FirstCell Is Nothing Then
Set FirstCell = myCell
End If
End If
Next myCell

If RealCellCount 1 Then
'what to do, more than one cell updated
Else
MsgBox FirstCell.Address
Call IsErasingCell("a", FirstCell)
End If

End Sub
Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
IsErasingCell = False
If Trim(Previous) < "" _
And Trim(target.Value) = "" Then
IsErasingCell = True
End If
End Function




clara wrote:

hi Tom,

I have a merged cell and using with a data validation. I use the following
function to check whether the cell's content is empty:

Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
If Trim(Previous) < "" And Trim(target.Value) = "" Then IsErasingCell =
True
End Function

previous is the value of the cell before change. I test with Spacebar,
Backspace and the empty value in data validation, they all work well, but
when I press Delete key, i got error message: Type mismatch. why?

Clara

thank you so much for your help

"Tom Ogilvy" wrote:

why would you think using the delete key would not pass that test?

Do you mean the user had deleted multiple cells?

If target.count 1 then exit sub

at the start of your routine or figure out how you want to handle when
Target includes more than one cell.


--
Regards,
Tom Ogilvy


"clara" wrote:

Hi all,

in change event, I can use trim(target.value) ="" to tell a user is erasing
a cell content until the Delete was pressed. How can I handle it?

Clara
--
thank you so much for your help


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Delete key casue a litte trouble

Hi Dave,

Thank you very much for your code. One question is when the RealCellCount 1


Clara
--
thank you so much for your help


"Dave Peterson" wrote:

Mergecells are a pain.

If you change put something into a merged cell, then the single cell is passed
to the event.

If you clear the merge area, then the whole mergearea is passed to the event.

Do yourself a big favor and stop using merged cells <vbg.

Maybe you can pick something out of this:

Option Explicit
Private Sub Worksheet_Change(ByVal target As Range)

Dim RealCellCount As Long
Dim myCell As Range
Dim FirstCell As Range

RealCellCount = 0
Set FirstCell = Nothing
For Each myCell In target.Cells
If myCell.MergeCells Then
If myCell.MergeArea.Cells(1).Address = myCell.Address Then
RealCellCount = RealCellCount + 1
If FirstCell Is Nothing Then
Set FirstCell = myCell
End If
End If
Else
RealCellCount = RealCellCount + 1
If FirstCell Is Nothing Then
Set FirstCell = myCell
End If
End If
Next myCell

If RealCellCount 1 Then
'what to do, more than one cell updated
Else
MsgBox FirstCell.Address
Call IsErasingCell("a", FirstCell)
End If

End Sub
Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
IsErasingCell = False
If Trim(Previous) < "" _
And Trim(target.Value) = "" Then
IsErasingCell = True
End If
End Function




clara wrote:

hi Tom,

I have a merged cell and using with a data validation. I use the following
function to check whether the cell's content is empty:

Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
If Trim(Previous) < "" And Trim(target.Value) = "" Then IsErasingCell =
True
End Function

previous is the value of the cell before change. I test with Spacebar,
Backspace and the empty value in data validation, they all work well, but
when I press Delete key, i got error message: Type mismatch. why?

Clara

thank you so much for your help

"Tom Ogilvy" wrote:

why would you think using the delete key would not pass that test?

Do you mean the user had deleted multiple cells?

If target.count 1 then exit sub

at the start of your routine or figure out how you want to handle when
Target includes more than one cell.


--
Regards,
Tom Ogilvy


"clara" wrote:

Hi all,

in change event, I can use trim(target.value) ="" to tell a user is erasing
a cell content until the Delete was pressed. How can I handle it?

Clara
--
thank you so much for your help


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete key casue a litte trouble

RealCellCount wasn't a real <bg good variable name.

I meant it to represent the number of cells that are actually changing--when
each mergearea is counted as a single cell.

But it was the best I could think of yesterday!

clara wrote:

Hi Dave,

Thank you very much for your code. One question is when the RealCellCount 1

Clara
--
thank you so much for your help

"Dave Peterson" wrote:

Mergecells are a pain.

If you change put something into a merged cell, then the single cell is passed
to the event.

If you clear the merge area, then the whole mergearea is passed to the event.

Do yourself a big favor and stop using merged cells <vbg.

Maybe you can pick something out of this:

Option Explicit
Private Sub Worksheet_Change(ByVal target As Range)

Dim RealCellCount As Long
Dim myCell As Range
Dim FirstCell As Range

RealCellCount = 0
Set FirstCell = Nothing
For Each myCell In target.Cells
If myCell.MergeCells Then
If myCell.MergeArea.Cells(1).Address = myCell.Address Then
RealCellCount = RealCellCount + 1
If FirstCell Is Nothing Then
Set FirstCell = myCell
End If
End If
Else
RealCellCount = RealCellCount + 1
If FirstCell Is Nothing Then
Set FirstCell = myCell
End If
End If
Next myCell

If RealCellCount 1 Then
'what to do, more than one cell updated
Else
MsgBox FirstCell.Address
Call IsErasingCell("a", FirstCell)
End If

End Sub
Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
IsErasingCell = False
If Trim(Previous) < "" _
And Trim(target.Value) = "" Then
IsErasingCell = True
End If
End Function




clara wrote:

hi Tom,

I have a merged cell and using with a data validation. I use the following
function to check whether the cell's content is empty:

Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
If Trim(Previous) < "" And Trim(target.Value) = "" Then IsErasingCell =
True
End Function

previous is the value of the cell before change. I test with Spacebar,
Backspace and the empty value in data validation, they all work well, but
when I press Delete key, i got error message: Type mismatch. why?

Clara

thank you so much for your help

"Tom Ogilvy" wrote:

why would you think using the delete key would not pass that test?

Do you mean the user had deleted multiple cells?

If target.count 1 then exit sub

at the start of your routine or figure out how you want to handle when
Target includes more than one cell.


--
Regards,
Tom Ogilvy


"clara" wrote:

Hi all,

in change event, I can use trim(target.value) ="" to tell a user is erasing
a cell content until the Delete was pressed. How can I handle it?

Clara
--
thank you so much for your help


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Delete key casue a litte trouble

Hi Dave,

I got answer to my last question.

Thank you very much!!

Clara


--
thank you so much for your help


"Dave Peterson" wrote:

Mergecells are a pain.

If you change put something into a merged cell, then the single cell is passed
to the event.

If you clear the merge area, then the whole mergearea is passed to the event.

Do yourself a big favor and stop using merged cells <vbg.

Maybe you can pick something out of this:

Option Explicit
Private Sub Worksheet_Change(ByVal target As Range)

Dim RealCellCount As Long
Dim myCell As Range
Dim FirstCell As Range

RealCellCount = 0
Set FirstCell = Nothing
For Each myCell In target.Cells
If myCell.MergeCells Then
If myCell.MergeArea.Cells(1).Address = myCell.Address Then
RealCellCount = RealCellCount + 1
If FirstCell Is Nothing Then
Set FirstCell = myCell
End If
End If
Else
RealCellCount = RealCellCount + 1
If FirstCell Is Nothing Then
Set FirstCell = myCell
End If
End If
Next myCell

If RealCellCount 1 Then
'what to do, more than one cell updated
Else
MsgBox FirstCell.Address
Call IsErasingCell("a", FirstCell)
End If

End Sub
Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
IsErasingCell = False
If Trim(Previous) < "" _
And Trim(target.Value) = "" Then
IsErasingCell = True
End If
End Function




clara wrote:

hi Tom,

I have a merged cell and using with a data validation. I use the following
function to check whether the cell's content is empty:

Public Function IsErasingCell(Previous As Variant, target As Range) As Boolean
If Trim(Previous) < "" And Trim(target.Value) = "" Then IsErasingCell =
True
End Function

previous is the value of the cell before change. I test with Spacebar,
Backspace and the empty value in data validation, they all work well, but
when I press Delete key, i got error message: Type mismatch. why?

Clara

thank you so much for your help

"Tom Ogilvy" wrote:

why would you think using the delete key would not pass that test?

Do you mean the user had deleted multiple cells?

If target.count 1 then exit sub

at the start of your routine or figure out how you want to handle when
Target includes more than one cell.


--
Regards,
Tom Ogilvy


"clara" wrote:

Hi all,

in change event, I can use trim(target.value) ="" to tell a user is erasing
a cell content until the Delete was pressed. How can I handle it?

Clara
--
thank you so much for your help


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Litte more advanced question Chad Excel Discussion (Misc queries) 1 January 30th 09 06:30 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 1 June 22nd 05 01:12 AM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:11 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


All times are GMT +1. The time now is 02:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"