Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Help with changing code

I found this post by Dave Peterson in 2007. I want to set some conditional
number formatting similar to how this code works but want to execute the code
for columns d through o. I tried changing Me.Range("a:a") with
Me.Range("d:o") and got a compile error: "invalid use of me keyword".

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRng As Range
Dim myCell As Range

Set myRng = Intersect(Target, Me.Range("a:a"))

If myRng Is Nothing Then
Exit Sub
End If

For Each myCell In myRng.Cells
If IsNumeric(myCell.Value) Then
If Int(myCell.Value) = myCell.Value Then
myCell.NumberFormat = "General"
Else
myCell.NumberFormat = "#,##0.0000"
End If
End If
Next myCell

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,805
Default Help with changing code

I copied the code and changed the range to "d:o" like this
Set myRng = Intersect(Target, Me.Range("d:o"))

and it worked fine...

"Steve" wrote:

I found this post by Dave Peterson in 2007. I want to set some conditional
number formatting similar to how this code works but want to execute the code
for columns d through o. I tried changing Me.Range("a:a") with
Me.Range("d:o") and got a compile error: "invalid use of me keyword".

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRng As Range
Dim myCell As Range

Set myRng = Intersect(Target, Me.Range("a:a"))

If myRng Is Nothing Then
Exit Sub
End If

For Each myCell In myRng.Cells
If IsNumeric(myCell.Value) Then
If Int(myCell.Value) = myCell.Value Then
myCell.NumberFormat = "General"
Else
myCell.NumberFormat = "#,##0.0000"
End If
End If
Next myCell

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Help with changing code

Good for you! Unfortunately, that doesn't help me much.

"Sheeloo" wrote:

I copied the code and changed the range to "d:o" like this
Set myRng = Intersect(Target, Me.Range("d:o"))

and it worked fine...

"Steve" wrote:

I found this post by Dave Peterson in 2007. I want to set some conditional
number formatting similar to how this code works but want to execute the code
for columns d through o. I tried changing Me.Range("a:a") with
Me.Range("d:o") and got a compile error: "invalid use of me keyword".

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRng As Range
Dim myCell As Range

Set myRng = Intersect(Target, Me.Range("a:a"))

If myRng Is Nothing Then
Exit Sub
End If

For Each myCell In myRng.Cells
If IsNumeric(myCell.Value) Then
If Int(myCell.Value) = myCell.Value Then
myCell.NumberFormat = "General"
Else
myCell.NumberFormat = "#,##0.0000"
End If
End If
Next myCell

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Help with changing code

This code is an event handler.

If you're changing the cells in columns D:0 manually, then this event will fire
for each of those changes.

But you have to put the code behind the worksheet that should have this
behavior.

Rightclick on the worksheet tab and select view code.

Paste the code in the code window (usually the righthand side) of the window
that just opened up.

And remove the code from where you had placed it before.

Steve wrote:

I found this post by Dave Peterson in 2007. I want to set some conditional
number formatting similar to how this code works but want to execute the code
for columns d through o. I tried changing Me.Range("a:a") with
Me.Range("d:o") and got a compile error: "invalid use of me keyword".

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRng As Range
Dim myCell As Range

Set myRng = Intersect(Target, Me.Range("a:a"))

If myRng Is Nothing Then
Exit Sub
End If

For Each myCell In myRng.Cells
If IsNumeric(myCell.Value) Then
If Int(myCell.Value) = myCell.Value Then
myCell.NumberFormat = "General"
Else
myCell.NumberFormat = "#,##0.0000"
End If
End If
Next myCell

End Sub


--

Dave Peterson
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
changing zip code to number John K Excel Discussion (Misc queries) 3 November 21st 08 10:42 PM
changing format code?? please help!!! laandmc Excel Discussion (Misc queries) 2 September 24th 08 09:58 PM
Changing ZIP code formats in Excel 2003 cdbinder Excel Discussion (Misc queries) 6 January 29th 07 03:04 AM
Changing the code on an external link. sungen99 Excel Discussion (Misc queries) 1 May 25th 06 03:30 PM
code for changing font Jack Sons Excel Discussion (Misc queries) 2 November 22nd 05 06:42 PM


All times are GMT +1. The time now is 07:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"