ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using case (https://www.excelbanter.com/excel-programming/415673-using-case.html)

Risky Dave

Using case
 
Hi,

From the worksheet code window, I am trying to identify when certain cells
are modified and execute various functions according to different criteria.

I am trying to do this by using a case statement based on the value of
Target.Column, but nothing seems to be happening (no errors coming up, but
not the result I was expecting either).

I have:

Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Target
Case Target.Column = 3
MsgBox ("column" & Target.Column)
Case Target.Column = 4
MsgBox("column" & Target.Column)
End Select

Obviously, in the final code, MsgBox willbe replaced by stuff that actually
does useful things, but for now can someone tell me how to get this working,
and if it won't how can I achieve this sort of result (it needs to be based
on the column modified)

TIA

Dave

Mike H

Using case
 
You were very close

Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Target.Column
Case Is = 3
MsgBox ("column" & Target.Column)
Case Is = 4
MsgBox ("column" & Target.Column)
Case Else
'Do something else
End Select

End Sub


Mike

"Risky Dave" wrote:

Hi,

From the worksheet code window, I am trying to identify when certain cells
are modified and execute various functions according to different criteria.

I am trying to do this by using a case statement based on the value of
Target.Column, but nothing seems to be happening (no errors coming up, but
not the result I was expecting either).

I have:

Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Target
Case Target.Column = 3
MsgBox ("column" & Target.Column)
Case Target.Column = 4
MsgBox("column" & Target.Column)
End Select

Obviously, in the final code, MsgBox willbe replaced by stuff that actually
does useful things, but for now can someone tell me how to get this working,
and if it won't how can I achieve this sort of result (it needs to be based
on the column modified)

TIA

Dave


Risky Dave

Using case
 
Mike,

My thanks.

One day I'll get the hang of this :-)


Dave
"Mike H" wrote:

You were very close

Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Target.Column
Case Is = 3
MsgBox ("column" & Target.Column)
Case Is = 4
MsgBox ("column" & Target.Column)
Case Else
'Do something else
End Select

End Sub


Mike

"Risky Dave" wrote:

Hi,

From the worksheet code window, I am trying to identify when certain cells
are modified and execute various functions according to different criteria.

I am trying to do this by using a case statement based on the value of
Target.Column, but nothing seems to be happening (no errors coming up, but
not the result I was expecting either).

I have:

Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Target
Case Target.Column = 3
MsgBox ("column" & Target.Column)
Case Target.Column = 4
MsgBox("column" & Target.Column)
End Select

Obviously, in the final code, MsgBox willbe replaced by stuff that actually
does useful things, but for now can someone tell me how to get this working,
and if it won't how can I achieve this sort of result (it needs to be based
on the column modified)

TIA

Dave


Don Guillett

Using case
 
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "Column " & Target.Column
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Risky Dave" wrote in message
...
Hi,

From the worksheet code window, I am trying to identify when certain cells
are modified and execute various functions according to different
criteria.

I am trying to do this by using a case statement based on the value of
Target.Column, but nothing seems to be happening (no errors coming up, but
not the result I was expecting either).

I have:

Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Target
Case Target.Column = 3
MsgBox ("column" & Target.Column)
Case Target.Column = 4
MsgBox("column" & Target.Column)
End Select

Obviously, in the final code, MsgBox willbe replaced by stuff that
actually
does useful things, but for now can someone tell me how to get this
working,
and if it won't how can I achieve this sort of result (it needs to be
based
on the column modified)

TIA

Dave




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com