LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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.
 
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 05:07 PM.

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"