Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Fill down problem with Worksheet_Change(ByVal Target As Range)

Hi

I have a problem when trying to use "fill down" in an excel sheet where I am
using a Worksheet_Change() program to update some cells. The program looks
like:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NoDoc

If Target.Row 4 Then
Select Case Target.Column
Case 29
NoDoc = "No Doc."
= If Target.Offset(0, 0) < NoDoc And Target.Offset(0, -4) = "" Then
Target.Offset(0, -4) = "XXXXXX"
ElseIf Target.Offset(0, 0) = NoDoc Then
Target.Offset(0, -4) = ""
End If
End Select
End If
End Sub

The errormessage is "Runtime error 13 - Type Mitchmatch". The Sub is working
okay when only change one cell at a time - the error arrices when cliking a
cell and draging it down.

Can anyone help?

/Steen
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Fill down problem with Worksheet_Change(ByVal Target As Range)

Hi
If you select more than one cell, your conditions on Target do not make
sense. You need to check the conditions in each Cell of target.
Target.row still makes sense, and returns the first row in the range
Target.
Try this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NoDoc As String
Dim Cell as range
If Target.Row 4 Then
Select Case Target.Column
Case 29
NoDoc = "No Doc."
For Each cell In Target
If cell < NoDoc And cell.Offset(0, -4) = "" Then
cell.Offset(0, -4) = "XXXXXX"
ElseIf cell = NoDoc Then
cell.Offset(0, -4) = ""
End If
Next cell
End Select
End If
End Sub

regards
Paul

Steen wrote:

Hi

I have a problem when trying to use "fill down" in an excel sheet where I am
using a Worksheet_Change() program to update some cells. The program looks
like:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NoDoc

If Target.Row 4 Then
Select Case Target.Column
Case 29
NoDoc = "No Doc."
= If Target.Offset(0, 0) < NoDoc And Target.Offset(0, -4) = "" Then
Target.Offset(0, -4) = "XXXXXX"
ElseIf Target.Offset(0, 0) = NoDoc Then
Target.Offset(0, -4) = ""
End If
End Select
End If
End Sub

The errormessage is "Runtime error 13 - Type Mitchmatch". The Sub is working
okay when only change one cell at a time - the error arrices when cliking a
cell and draging it down.

Can anyone help?

/Steen


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Fill down problem with Worksheet_Change(ByVal Target As Range)

Hi Poul

Thanks - works wery well :-)

/Steen

" wrote:

Hi
If you select more than one cell, your conditions on Target do not make
sense. You need to check the conditions in each Cell of target.
Target.row still makes sense, and returns the first row in the range
Target.
Try this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NoDoc As String
Dim Cell as range
If Target.Row 4 Then
Select Case Target.Column
Case 29
NoDoc = "No Doc."
For Each cell In Target
If cell < NoDoc And cell.Offset(0, -4) = "" Then
cell.Offset(0, -4) = "XXXXXX"
ElseIf cell = NoDoc Then
cell.Offset(0, -4) = ""
End If
Next cell
End Select
End If
End Sub

regards
Paul

Steen wrote:

Hi

I have a problem when trying to use "fill down" in an excel sheet where I am
using a Worksheet_Change() program to update some cells. The program looks
like:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NoDoc

If Target.Row 4 Then
Select Case Target.Column
Case 29
NoDoc = "No Doc."
= If Target.Offset(0, 0) < NoDoc And Target.Offset(0, -4) = "" Then
Target.Offset(0, -4) = "XXXXXX"
ElseIf Target.Offset(0, 0) = NoDoc Then
Target.Offset(0, -4) = ""
End If
End Select
End If
End Sub

The errormessage is "Runtime error 13 - Type Mitchmatch". The Sub is working
okay when only change one cell at a time - the error arrices when cliking a
cell and draging it down.

Can anyone help?

/Steen



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
REPSOT?? Sub Worksheet_Change(ByVal Target As Range) Ed Davis[_2_] Excel Discussion (Misc queries) 14 October 13th 09 03:20 PM
Sub Worksheet_Change(ByVal Target As Excel.Range) Questions Wescotte Excel Programming 3 June 29th 05 10:53 PM
Worksheet_Change(ByVal Target As Excel.Range) Daggi Excel Programming 3 June 29th 05 02:59 PM
Private Sub Worksheet_Change(ByVal Target As Range) Arturo Excel Programming 1 May 25th 05 03:32 PM
Many Sub Worksheet_Change(ByVal Target As Range) In One Worksheet MathewPBennett Excel Programming 4 December 24th 03 01:01 PM


All times are GMT +1. The time now is 07:00 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"