mulholm

New Member
Joined
Jul 2, 2018
Messages
49
I found this code on the internet which works when dealing with one individual cell however stops working when values are pasted in to multiple cells at once. Can anyone help?


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$I$3" Then
'disable events
Application.EnableEvents = False
Range("I3").Value = Range("I3").Value / 86400

End If

'reenable events
Application.EnableEvents = True
Exit Sub
'error handler
ErrHnd:
Err.Clear
'reenable events
Application.EnableEvents = True

End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Welcome to the Board!

What range do you want to apply it to?
If all of column I, then you can do something like this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    
'   Check for cells pasted in column I
    Set rng = Intersect(Target, Columns("I:I"))
    
'   Exit if no cells in column I updated
    If rng Is Nothing Then Exit Sub
    
'   Disable events
    Application.EnableEvents = False
    
'   Loop through all updated cells in column I
    For Each cell In rng
        cell = cell.Value / 86400
    Next cell

'   Reenable events
    Application.EnableEvents = True

    Exit Sub

'error handler
ErrHnd:
    Err.Clear
'   Reenable events
    Application.EnableEvents = True

End Sub
Note: I also see that you have error handling code, but are not calling it anywhere in your code. So it won't do much in that case.
 
Upvote 0
Welcome to the Board!

What range do you want to apply it to?
If all of column I, then you can do something like this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    
'   Check for cells pasted in column I
    Set rng = Intersect(Target, Columns("I:I"))
    
'   Exit if no cells in column I updated
    If rng Is Nothing Then Exit Sub
    
'   Disable events
    Application.EnableEvents = False
    
'   Loop through all updated cells in column I
    For Each cell In rng
        cell = cell.Value / 86400
    Next cell

'   Reenable events
    Application.EnableEvents = True

    Exit Sub

'error handler
ErrHnd:
    Err.Clear
'   Reenable events
    Application.EnableEvents = True

End Sub
Note: I also see that you have error handling code, but are not calling it anywhere in your code. So it won't do much in that case.



It would be for range I3:I26
 
Upvote 0
It would be for range I3:I26
Then simply change this line to suit your range.
Code:
    Set rng = Intersect(Target, Columns("I:I"))

Change to this:
Code:
    Set rng = Intersect(Target, [COLOR=#ff0000]Range("I3:I26")[/COLOR])
 
Upvote 0
Then simply change this line to suit your range.
Code:
    Set rng = Intersect(Target, Columns("I:I"))

Change to this:
Code:
    Set rng = Intersect(Target, [COLOR=#ff0000]Range("I3:I26")[/COLOR])

thank you so much, appreciate your help
 
Upvote 0
You are welcome!:)
 
Upvote 0

Forum statistics

Threads
1,216,037
Messages
6,128,442
Members
449,453
Latest member
jayeshw

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