x2 codes to run simultaneously help

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
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

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.
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,214,858
Messages
6,121,956
Members
449,057
Latest member
FreeCricketId

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