View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JulieD JulieD is offline
external usenet poster
 
Posts: 618
Default Changing cell values

Hi

when you choose the CHANGE event from the procedure drop down in the VBE
window it should have created it like this

Private Sub Worksheet_Change(ByVal Target As Range)

and your code should then reference the TARGET object not the activecell
e.g.

Private Sub Worksheet_Change(ByVal Target As Range)

IF Intersect(Target,Me.Range("A1:A100")) is Nothing Then Exit Sub

SELECT CASE Target.value
Case "Alabama"
Target.value = "AL"
Case = "Alaska"
Target.Value = "AK"
'repeat structure for all 50 states then
END SELECT

End sub
------

change the A1:A100 to cover the range that your drop down boxes are in


--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"D" wrote in message
...
Ok.
I don't know where it failed because I didn't get an error that it did
fail
but here is the first lines of code for the states. When I put that text
in
a cell nothing happens its just the word for example if I put in Alabama
in a
cell it won't change to AL it just stays Alabama.
Of course at the bottom there is an End If and an End Sub. So here it is.

Private Sub Worksheet_Change()

If ActiveCell.Value = "Alabama" Then
ActiveCell.Value = "AL"
ElseIf ActiveCell.Value = "Alaska" Then
ActiveCell.Value = "AK"
ElseIf ActiveCell.Value = "Arizona" Then
ActiveCell.Value = "AZ"
ElseIf ActiveCell.Value = "Arkansas" Then
ActiveCell.Value = "AK"
ElseIf ActiveCell.Value = "California" Then
ActiveCell.Value = "CA"
ElseIf ActiveCell.Value = "Colorado" Then
ActiveCell.Value = "CO"
ElseIf ActiveCell.Value = "Connecticut" Then
ActiveCell.Value = "CT"
ElseIf ActiveCell.Value = "Delaware" Then
ActiveCell.Value = "DE"
And the list goes on.
Thanks for you help!
Let me know if you need any other information from the code but that is
basically all that I have.

"JulieD" wrote:

okay so what happened when you put a breakpoint on the first line of your
code and changed a state & then stepped through the code, where it did
"fail" ... give me that line and the lines above and we might be able to
figure out a solution ...

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"D" wrote in message
...
Well the security is not an issue because I have done macros before,
and
the
setting is set to "Low" because I don't want to deal with it. Anyways,
I
did
up an event in "ThisWorkbook" as a Private Sub Worksheet_Change and
then I
have the if and ifelse statements for the states and the abbreviations.
I
don't think you want the whole code because it is very long with all 50
states. I am not getting any errors its just that when I change the
cell
it
doesn't switch the text to the abbreviation. It doesn't do anything.
Hope
you
can help.
Thanks,
D

"JulieD" wrote:

Hi

if you'ld to post all your code then it might help figure out a
solution
.... things to check in the meantime
tools / macro / macros - security set to medium or less and you choose
enable macros on open
in the immediate window type (VBE Window / view / immediate window)
application.enableevents = true
and press enter


--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"D" wrote in message
...
Hello.
I have a cell list of states, from data validation, that a user
created
and
now would like when a user types the state or selects the state from
a
drop-down list, it converts it to the abbreviation of the state. I
have
an
If
ActiveCell.Value = "Alabama" Then
ActiveCell.Value = "AL"
but it doesn't seem to be working. ??? Don't know why? I thought
this
would
be easy but not sure now. Well hope you can help.
Thanks,
--
D