Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
raj raj is offline
external usenet poster
 
Posts: 32
Default On change event

Hello. Please help me if you can.

I'm trying to set up an on sheet change, which I can get
to fire, but not successfully.

My code is supposed to reformat a range of cells from this:

123123123412345612312123

to this:

123.123.1234.123456.123.12.123

It must also ensure that the pattern is entered correctly,
i.e. not text or a partial set of values, etc.

Here is my code in a sheet module (you should be able to
copy directly to a module):

Private Sub Worksheet_Calculate()

Dim rngCell As Range

For Each rngCell In Range("A24:A30").Rows
If Not rngCell.FormulaR1C1 = "" And Not _
rngCell.FormulaR1C1
Like "###.###.####.######.###.##.###" Then
rngCell.Activate
MsgBox "Invalid account distribution!",
vbCritical, _
"INVALID ACCOUNT DISTRIBUTION!": Exit Sub
End If
Next rngCell

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)

Dim rngCell As Range
Dim strAccount As String

For Each rngCell In Range("A24:A30").Rows
If rngCell.FormulaR1C1 Like "########################"
Then
strAccount = rngCell.FormulaR1C1
strAccount = Left(strAccount, 3) & "." & _
Mid(strAccount, 4, 3) & "." & _
Mid(strAccount, 7, 4) & "." & _
Mid(strAccount, 11, 6) & "." & _
Mid(strAccount, 17, 3) & "." & _
Mid(strAccount, 20, 2) & "." & _
Right(strAccount, 3)
rngCell.FormulaR1C1 = strAccount
End If
Next rngCell

End Sub

Your example code would be most helpful. Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default On change event

Raj

I'm not sure you can do what you want. I don't think you can have a number
with 24 digits.

If for example, you enter 123456789012345678901234, a 24 digit number, Excel
will display it as 1.23456789012345E+23 in the formula bar and 1.234567E+23
in the cell. That's with format general. If you change it to numeric
format it then displays as 1.23456789012345E+23 in the formula bar and
1.23456789012345000000000.00 in the cell.

So I don't think you can have the format you want is the shorter answer.
Probably something to do with 15 digits precision.

Regards

Trevor


"raj" wrote in message
...
Hello. Please help me if you can.

I'm trying to set up an on sheet change, which I can get
to fire, but not successfully.

My code is supposed to reformat a range of cells from this:

123123123412345612312123

to this:

123.123.1234.123456.123.12.123

It must also ensure that the pattern is entered correctly,
i.e. not text or a partial set of values, etc.

Here is my code in a sheet module (you should be able to
copy directly to a module):

Private Sub Worksheet_Calculate()

Dim rngCell As Range

For Each rngCell In Range("A24:A30").Rows
If Not rngCell.FormulaR1C1 = "" And Not _
rngCell.FormulaR1C1
Like "###.###.####.######.###.##.###" Then
rngCell.Activate
MsgBox "Invalid account distribution!",
vbCritical, _
"INVALID ACCOUNT DISTRIBUTION!": Exit Sub
End If
Next rngCell

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)

Dim rngCell As Range
Dim strAccount As String

For Each rngCell In Range("A24:A30").Rows
If rngCell.FormulaR1C1 Like "########################"
Then
strAccount = rngCell.FormulaR1C1
strAccount = Left(strAccount, 3) & "." & _
Mid(strAccount, 4, 3) & "." & _
Mid(strAccount, 7, 4) & "." & _
Mid(strAccount, 11, 6) & "." & _
Mid(strAccount, 17, 3) & "." & _
Mid(strAccount, 20, 2) & "." & _
Right(strAccount, 3)
rngCell.FormulaR1C1 = strAccount
End If
Next rngCell

End Sub

Your example code would be most helpful. Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default On change event

You got a couple responses yesterday:
http://groups.google.com/groups?thre...5FF6%40msn.com

(Are you punchy?)

raj wrote:

Hello. Please help me if you can.

I'm trying to set up an on sheet change, which I can get
to fire, but not successfully.

My code is supposed to reformat a range of cells from this:

123123123412345612312123

to this:

123.123.1234.123456.123.12.123

It must also ensure that the pattern is entered correctly,
i.e. not text or a partial set of values, etc.

Here is my code in a sheet module (you should be able to
copy directly to a module):

Private Sub Worksheet_Calculate()

Dim rngCell As Range

For Each rngCell In Range("A24:A30").Rows
If Not rngCell.FormulaR1C1 = "" And Not _
rngCell.FormulaR1C1
Like "###.###.####.######.###.##.###" Then
rngCell.Activate
MsgBox "Invalid account distribution!",
vbCritical, _
"INVALID ACCOUNT DISTRIBUTION!": Exit Sub
End If
Next rngCell

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)

Dim rngCell As Range
Dim strAccount As String

For Each rngCell In Range("A24:A30").Rows
If rngCell.FormulaR1C1 Like "########################"
Then
strAccount = rngCell.FormulaR1C1
strAccount = Left(strAccount, 3) & "." & _
Mid(strAccount, 4, 3) & "." & _
Mid(strAccount, 7, 4) & "." & _
Mid(strAccount, 11, 6) & "." & _
Mid(strAccount, 17, 3) & "." & _
Mid(strAccount, 20, 2) & "." & _
Right(strAccount, 3)
rngCell.FormulaR1C1 = strAccount
End If
Next rngCell

End Sub

Your example code would be most helpful. Thanks in advance.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default On change event


I think he's right dave...


---
~~ Message posted from http://www.ExcelForum.com/

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
change event smonsmo Excel Discussion (Misc queries) 1 June 8th 07 09:31 PM
Change event Macro Mike Rogers Excel Discussion (Misc queries) 1 August 20th 06 05:29 AM
Change event? Mike Rogers Excel Discussion (Misc queries) 2 January 5th 06 01:46 AM
Change of Row event crazybass2 Excel Discussion (Misc queries) 7 December 7th 04 06:21 PM
change event/after update event?? scrabtree23[_2_] Excel Programming 1 October 20th 03 07:09 PM


All times are GMT +1. The time now is 09:35 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"