The following Event works very well without any errors. It loops through 'wscf' and…
- User
The following Event works very well without any errors. It loops through 'wscf' and copies the requested values to 'wsjr' in column D. What I would like to add to the event is the following condition: When it loops through 'wscf' it should also check if the value in column B of the same row is 'Service'. If the value in column B of the same row is 'Service' then it should CONCATENATE the value of column J and column H with a space in between the two values.
Sub OutstandingJobs()
Application.EnableEvents = False Application.ScreenUpdating = False
Dim wscf As Worksheet Dim wsjr As Worksheet Dim lastRow As Long Dim copyRange As Range Dim i As Long
ActiveSheet.Range("D9:D14").ClearContents
Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.Range("I2").formula = ActiveSheet.Range("I2").formula
Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.Range("H3").formula = ActiveSheet.Range("H3").formula
If ActiveSheet.Range("I2") = "" Or 0 Then
Application.ScreenUpdating = True Application.EnableEvents = True
Exit Sub End If
Application.EnableEvents = False Application.ScreenUpdating = False
Set wscf = Sheets(Range("I2").Value) Set wsjr = Sheets("Job Request") lastRow = wscf.Cells(Rows.count, "J").End(xlUp).Row
For i = 5 To lastRow If wscf.Cells(i, "I") = "" Then
If copyRange Is Nothing Then Set copyRange = wscf.Range("J" & i)
Application.ScreenUpdating = True Application.EnableEvents = True
Else Set copyRange = Union(copyRange, wscf.Range("J" & i))
Application.ScreenUpdating = True Application.EnableEvents = True
End If End If Next i
If Not copyRange Is Nothing Then wsjr.Range("D9").Resize(copyRange.Rows.count, 1).Value = copyRange.Value End If
Application.ScreenUpdating = True Application.EnableEvents = True Call FixedRates End Sub
- Assistant
Sub OutstandingJobs()
Application.EnableEvents = False Application.ScreenUpdating = False
Dim wscf As Worksheet Dim wsjr As Worksheet Dim lastRow As Long Dim copyRange As Range Dim i As Long
ActiveSheet.Range("D9:D14").ClearContents
Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.Range("I2").formula = ActiveSheet.Range("I2").formula
Application.Wait (Now + TimeValue("0:00:01"))
ActiveSheet.Range("H3").formula = ActiveSheet.Range("H3").formula
If ActiveSheet.Range("I2") = "" Or 0 Then
Application.ScreenUpdating = True Application.EnableEvents = True
- User
The event is now only copying across, multiple instances of the requested value in column J that does not have the value 'Service' in column B of the same row. All conditions that have the value 'Service' in column B of the same row are not being copied over
- Assistant
Apologies for the confusion. It seems I misunderstood your requirements. To achieve the desired behavior, you can modify the code as follows:
For i = 5 To lastRow If wscf.Cells(i, "I") = "" Then If wscf.Cells(i, "B") = "Service" Then Dim concatenatedValue As String concatenatedValue = wscf.Cells(i, "J") & " " & wscf.Cells(i, "H") If copyRange Is Nothing Then Set copyRange = wscf.Range("J" & i) copyRange.Value = concatenatedValue Else Set copyRange = Union(copyRange, wscf.Range("J" & i)) copyRange.Value = concatenatedValue End If Else If copyRange Is Nothing Then Set copyRange = wscf.Range("J" & i) copyRange.Value = wscf.Cells(i, "J") Else Set copyRange = Union(copyRange, wscf.Range("J" & i)) copyRange.Value = wscf.Cells(i, "J") End If End If End If Next iThis will check if the value in column B of the same row is "Service" and concatenate the values of column J and H if that condition is met. Otherwise, it will copy the value from column J as before.