View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Sinner Sinner is offline
external usenet poster
 
Posts: 142
Default Using xl MID function through VB.

On Feb 22, 3:07*pm, Incidental wrote:
Hi Sinner

I'm not sure why that is happening as if I delete a value in column C
the value in column J is also removed. *Did you change the code to fit
your needs or are you using the exact code I posted? *Let me know
either way or post your code and I will have a look. *I have changed
the code I posted earlier just to make it a little cleaner, I removed
one of the "If" statements as it was unnecessary.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Count = 1 Then

* * If Target.Column = 3 And Target.Row < 1 Then

* * * * Cells(Target.Row, 10).Value = "'" & Mid(Target.Value, 7, 3)

* * End If

End If

End Sub

Steve


Hi Steve,

I have already removed the extra if : )

You wrote:
"I'm not sure why that is happening as if I delete a value in column C
the value in column J is also removed."
For single value select it is working fine.
For more than one selection the code is unable to remove the value in
J.
For instance you select C114 & delete, then it is working but if you
select C114, C115, C116, C117 and delete, then values in corresponding
column J114, J115, J116 & J117 are not removed.

My guess is that Target.Count needs to be varied with selection of
cells.

My code is below.
---------------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Count = 1 Then

If Target.Column = 3 And Target.Row < 1 Then

Cells(Target.Row, 10).Value = Mid(Target.Value, 10, 3)

End If

End If


End Sub
---------------------------------

Thx.