Combining VBA Codes

jh3268

New Member
Joined
Mar 23, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Need some help combining 2 different VBA codes into my Excel sheet please.

Below are the separate codes for each and below that is what I have done to try to combine them and the error I am receiving. The top code is working but the bottom one is not. Not sure that it matters or not, but for the 2nd code, in order for column L to show "TRUE", it has to meet the following formula that I have in place: =IF(AND(TEXT(NOW()-B2,"[h]")*1>25,I2=""),TRUE,"")


Private Sub Worksheet_Change(ByVal Target As Range)

' Check to see only one cell updated
If Target.CountLarge > 1 Then Exit Sub

' Check to see if entry is made in column k after row 1 and is set to "YES"
If Target.Column = 11 And Target.Row > 1 And Target.Value = "YES" Then
Application.EnableEvents = False
' Copy columns A to L to complete sheet in next available row
Range(Cells(Target.Row, "A"), Cells(Target.Row, "L")).Copy Sheets("COMPLETED").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
' Delete current row after copied
Rows(Target.Row).Delete
Application.EnableEvents = True
End If

End Sub

------------------


Private Sub Worksheet_Changes(ByVal Target As Range)

' Check to see only one cell updated
If Target.CountLarge > 1 Then Exit Sub

' Check to see if entry is made in column L after row 1 and is set to "TRUE"
If Target.Column = 12 And Target.Row > 1 And Target.Value = "TRUE" Then
Application.EnableEvents = False
' Copy columns A to L to complete sheet in next available row
Range(Cells(Target.Row, "A"), Cells(Target.Row, "L")).Copy Sheets("SLA EXCEEDED").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
' Delete current row after copied
Rows(Target.Row).Delete
Application.EnableEvents = True
End If

End Sub
And here is currently what I have when I tried to combine the 2. I am getting a runtime error 424: Object required.
1715605044993.png
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
It looks like your formula is returning the boolean value of TRUE (no quotes) and not a text value of "TRUE".

So try removing the quotes from around the value of TRUE in your code, i.e.
VBA Code:
If Target.Column = 12 And Target.Row > 1 And Target.Value = TRUE Then
 
Upvote 0
Change these lines
VBA Code:
Application.EnableEvents = True
End If
If Target.Column = 12 And Target.Row > 1 And Target.Value = "TRUE" Then
to
VBA Code:
Application.EnableEvents = True
ElseIf Target.Column = 12 And Target.Row > 1 And Target.Value = "TRUE" Then
 
Upvote 0
It looks like your formula is returning the boolean value of TRUE (no quotes) and not a text value of "TRUE".

So try removing the quotes from around the value of TRUE in your code, i.e.
VBA Code:
If Target.Column = 12 And Target.Row > 1 And Target.Value = TRUE Then
Change these lines
VBA Code:
Application.EnableEvents = True
End If
If Target.Column = 12 And Target.Row > 1 And Target.Value = "TRUE" Then
to
VBA Code:
Application.EnableEvents = True
ElseIf Target.Column = 12 And Target.Row > 1 And Target.Value = "TRUE" Then
No error, but the 2nd code is still not working. Tried the "TRUE" with both quotes and without quotes as previously suggested as well.

1715607604595.png
 

Attachments

  • 1715606500431.png
    1715606500431.png
    50.6 KB · Views: 13
  • 1715607339934.png
    1715607339934.png
    51.5 KB · Views: 18
Upvote 0
Missed this bit
but for the 2nd code, in order for column L to show "TRUE", it has to meet the following formula that I have in place:
A worksheet change does not get triggered by a formula.
 
Upvote 0
Solution
A worksheet change does not get triggered by a formula.
Ah Monday morning! I looked right past that detail!
I was focusing too much on the error...
 
Upvote 0
Thank you both, I didn't realize this. Appreciate the help!
 
Upvote 0
You are welcome.

The only formula to fire when changes in calculated values happen is the "Worksheet_Calculate" event.
However, that has one big caveat -- "Worksheet_Calculate" cannot tell which cell's value changed, only that some cell somewhere on the sheet was re-calculated.
That is one nice thing about "Worksheet_Change" or "Worksheet_SelectionChange" is that they can tell you exactly which cell triggered the code to run (the "Target" cell).
But they only work with manual selections/changes.
 
Upvote 0

Forum statistics

Threads
1,223,950
Messages
6,175,582
Members
452,653
Latest member
craigje92

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