ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   using cell names in vb code (https://www.excelbanter.com/excel-programming/298886-using-cell-names-vbulletin-code.html)

bbxrider[_2_]

using cell names in vb code
 
excel 2000
trying to reference changed cells by their cell name in a case statement
with no luck
code is something like this, have tried target.range, target.name, etc
can't seem to find the right combination of target as and select case

Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Target.Range
Case Target.Range("cellName1"), Target.Range("cellName2"), etc
or
Select Case Target.name
Case Target.name("cellName1"), Target.name("cellName2"), etc

i'm thinking there is some way to do this, yes??????



Bob Umlas

using cell names in vb code
 
Try this:
Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error Resume Next 'in case target does NOT have a name!
Select Case Target.Name.Name 'yes, .Name.Name!
Case "CellName1", "CellName2"
.....
Case "MyName3"
...
End Select
End Sub

Bob Umlas
Excel MVP
"bbxrider" wrote in message
...
excel 2000
trying to reference changed cells by their cell name in a case statement
with no luck
code is something like this, have tried target.range, target.name, etc
can't seem to find the right combination of target as and select case

Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Target.Range
Case Target.Range("cellName1"), Target.Range("cellName2"), etc
or
Select Case Target.name
Case Target.name("cellName1"), Target.name("cellName2"), etc

i'm thinking there is some way to do this, yes??????





bbxrider[_2_]

using cell names in vb code
 
name.name is bizare but works, thanks a lot

"Bob Umlas" wrote in message
...
Try this:
Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error Resume Next 'in case target does NOT have a name!
Select Case Target.Name.Name 'yes, .Name.Name!
Case "CellName1", "CellName2"
.....
Case "MyName3"
...
End Select
End Sub

Bob Umlas
Excel MVP
"bbxrider" wrote in message
...
excel 2000
trying to reference changed cells by their cell name in a case statement
with no luck
code is something like this, have tried target.range, target.name, etc
can't seem to find the right combination of target as and select case

Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Target.Range
Case Target.Range("cellName1"), Target.Range("cellName2"), etc
or
Select Case Target.name
Case Target.name("cellName1"), Target.name("cellName2"), etc

i'm thinking there is some way to do this, yes??????








All times are GMT +1. The time now is 10:23 PM.

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