Multiple Worksheet_change

bedsy

New Member
Joined
Jun 29, 2016
Messages
34
Hi All,

Another day..... another issue.

I have a worksheet that I need to run multiple Worksheet_changes with.

The first part of the code to change range to uppercase works but the second portion of the code, meant to automatically change a cell from text to time format HH:MM does not..... keeps returning 0:00. for example if I enter 1330 it should change to 13:30.

Any thoughts??

Bedsy

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    
    On Error GoTo ErrHandler
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    If Not Intersect(Target, Range("A4:K27")) Is Nothing Then
        For Each rng In Intersect(Range("A4:K27"), Target)
            Target.Value = UCase(Target.Value)
        Next rng
    End If
   Set rng = Target.Parent.Range("H:H, I:I, K:K, L:L")
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Row < 2 Then Exit Sub
    If Intersect(Target, rng) Is Nothing Then
    
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        .Undo
    End With
    
    Target.Value = x / 1440
    Target.NumberFormat = "[h]:mm"
    
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
ExitHandler:
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Exit Sub
ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Note: slight change to above.

The Uppercase code works when run separately and the text to time returns 0:00 but once I have combined in the one workbook_change neither are functioning properly.

Master workbook.xlsm
ABCDEFGHIJK
1 ARRIVALSDepartures
2
3 OperatorCommodityFacilityIncoming IDPlanned Unit Planned Arr TimePlanned Unload TimeCompleted TimeOutgoing IDPlanned Unit Planned Dep Time
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Days Trains
 
Upvote 0
Thank you for the XL2BB (y) See if the following comes close to what you want:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("A4:K25"), Target) Is Nothing Then
        Application.EnableEvents = False
        If IsNumeric(Target) And Target <> "" Then
            Target = Format(Target, "00\:00")
        Else
            Target = UCase(Target)
        End If
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Thank you for the XL2BB (y) See if the following comes close to what you want:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("A4:K25"), Target) Is Nothing Then
        Application.EnableEvents = False
        If IsNumeric(Target) And Target <> "" Then
            Target = Format(Target, "00\:00")
        Else
            Target = UCase(Target)
        End If
        Application.EnableEvents = True
    End If
End Sub
OMG.... Looks so simple but I have been looking at this for days and just could not work it out. Over thinking it again.

The only issue is that column's D, G, I and J also have fields that contain just numbers and I do not require these as 00:00.

the time format only needs to apply to F, G, H, K
 
Upvote 0
Try this variation:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("A4:K25"), Target) Is Nothing Then
        Application.EnableEvents = False
        If Not Intersect(Target, Range("F:H,K:K")) Is Nothing And IsNumeric(Target) And Target <> "" Then
            Target = Format(Target, "00\:00")
        Else
            Target = UCase(Target)
        End If
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,970
Messages
6,175,726
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top