x2 codes to run simultaneously help

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hello the below code I hope you can help, I have the 2 codes below that need to run simultaneously, but at moment they don't, this is to work on a cell value change, the last code only works if you press play. hope you can help please. thex2 codes below are placed in sheet 8 (SMART Locate)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Range("H:h"), Target)
xOffsetColumn = -6
If Not WorkRng Is Nothing Then
    Application.EnableEvents = False
    For Each Rng In WorkRng
        If Not VBA.IsEmpty(Rng.Value) Then
            Rng.Offset(0, xOffsetColumn).Value = Now
            Rng.Offset(0, xOffsetColumn).NumberFormat = "dd/mm/yyyy hh:mm"
        Else
            Rng.Offset(0, xOffsetColumn).ClearContents
        End If
    Next
    Application.EnableEvents = True
End If
End Sub




Private Sub Initialise()

Dim emptyrow As Long
With ThisWorkbook.Sheets("SMART Locate")
    emptyrow = .Cells(Rows.Count, "H").End(xlUp).Row + 1
        .Cells(emptyrow, 10).Value = Environ("USERNAME")
      End With
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Only 1 code runs at a time, you can have the other code run inside the first code, but you have to call it.
 
Upvote 0
Sorry I am new to this. Where do I place this in the first code please? Does the rest stst the same?
 
Upvote 0
You can add the line to your original code to add the username to the range 10 cells over from the target(column R)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim WorkRng As Range
    Dim Rng As Range
    Dim xOffsetColumn As Integer

    Set WorkRng = Intersect(Range("H:H"), Target)
    xOffsetColumn = -6

    If Not WorkRng Is Nothing Then

        Application.EnableEvents = False

        For Each Rng In WorkRng

            If Not VBA.IsEmpty(Rng.Value) Then

                Rng.Offset(0, xOffsetColumn).Value = Format(Now, "dd/mm/yyyy hh:mm")
                Cells(Rng.Row, "R").Value = Environ("USERNAME")
            Else

                Rng.Offset(0, xOffsetColumn).ClearContents
                Cells(Rng.Row, "R").Value = ""
            End If

        Next

        Application.EnableEvents = True

    End If

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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