View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Susan Susan is offline
external usenet poster
 
Posts: 1,117
Default running change events to macros

as i'm sure you've discovered, you can only have one worksheet_change
macro. I'd suggest this........
put the individual programs in modules and name them something
different. then call them individually from the worksheet_change
macro.
like this:

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents=False

Call Lower_2_Upper
Call Month_Name

Application.EnableEvents = True

End Sub


Sub Lower_2_Upper()

If Target.Cells.Count 1 Then
Exit Sub
End If
On Error GoTo ErrHandler:
If Not Application.Intersect(Me.Range("C5:AG13"), Target) Is
Nothing Then
If IsNumeric(Target.Value) = False Then
' Application.EnableEvents = False
'Target.Value = StrConv(Target.Text, vbLowerCase)
Target.Value = StrConv(Target.Text, vbUpperCase)
'Target.Value = StrConv(Target.Text, vbProperCase)
' Application.EnableEvents = True
End If
End If
ErrHandler:
Application.EnableEvents = True

End Sub


Sub Month_Name()

For Dept = 1 To 3 Step 2
For MonthNum = 1 To 12
RangeName = MonthName(MonthNum, True) & "d" & Dept
If Not Intersect(target, Range(RangeName)) Is Nothing Then
DestRangeName = Dept & "d" & MonthName(MonthNum, True)
Range(RangeName).Copy _
Destination:=Sheets("Master Roster").Range(DestRangeName)
Exit Sub
End If
Next MonthNum
Next Dept

End Sub


hope that helps!
:)
susan


On Nov 21, 10:57*am, Dave ferris <Dave
wrote:
hi i'm new to vba and i'm struggling with this problem.
i have 2 event programs *which i wish to convert to macros so i can use an
event procedure to run these macros along with 2 others in order below is the
code for the event programs i wish to change.

the first one changes all lower case to upper case

Private Sub Worksheet_Change(ByVal Target As Range)
* * If Target.Cells.Count 1 Then
* * * * Exit Sub
* * End If
* * On Error GoTo ErrHandler:
* * If Not Application.Intersect(Me.Range("C5:AG13"), Target) Is Nothing Then
* * * * If IsNumeric(Target.Value) = False Then
* * * * * * Application.EnableEvents = False
* * * * * * 'Target.Value = StrConv(Target.Text, vbLowerCase)
* * * * * * Target.Value = StrConv(Target.Text, vbUpperCase)
* * * * * * 'Target.Value = StrConv(Target.Text, vbProperCase)
* * * * * * Application.EnableEvents = True
* * * * End If
* * End If
ErrHandler:
* * Application.EnableEvents = True
End Sub

this one copies a named range when a change is initiated then copies it to a
master worksheet with a similar named range.

Sub worksheet_change(ByVal target As Range)

For Dept = 1 To 3 Step 2
* For MonthNum = 1 To 12
* * *RangeName = MonthName(MonthNum, True) & "d" & Dept
* * *If Not Intersect(target, Range(RangeName)) Is Nothing Then
* * * * DestRangeName = Dept & "d" & MonthName(MonthNum, True)
* * * * Range(RangeName).Copy _
* * * * * *Destination:=Sheets("Master Roster").Range(DestRangeName)
* * * * Exit Sub
* * *End If
* Next MonthNum
Next Dept
End Sub

the other 2 macros are for changing the cell interior colours when a set
condition is met.

your help in this problem is very much appreciated
thank you