How do I add this code to below code?

Bret1

Board Regular
Joined
Jun 14, 2013
Messages
199
How do I add this.....
Code:
    Range("R17:S17").Select
    Selection.AutoFill Destination:=Range("R17:S2000"), Type:=xlFillDefault
    
    Range("A1").Select
End Sub

To This.......................... Note, I only want it to run the new addition when the main bottom code completes without the "else" function activated.
Code:
Sub Updating_Strikes_Macro()

Dim lr As Long
Dim r As Long

Application.ScreenUpdating = True

'Find last row in column J with data
lr = Cells(Rows.Count, "J").End(xlUp).Row

'Loop through all rows starting in row 17
For r = 17 To lr
'   If columns J and V are different and column J is not blank
    If (Cells(r, "J") <> Cells(r, "V")) And (Cells(r, "J") <> "") Then
'       Run code if they do not match
        Rows(r).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("A" & r & ":S" & r).Delete Shift:=xlUp
        Range("J" & r).Copy
        Range("V" & r).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("KB" & r).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    Else
'       If column J is blank and columns A and U are different
        If (Cells(r, "J") = "") And (Left(Cells(r, "A"), 5) <> Left(Cells(r, "U"), 5)) Then
'           What to do if columns A and U do not match
            MsgBox "Columns A and U do not match on row " & r, vbOKOnly, "MACRO STOPPED!!!"
            Exit Sub
        End If
    End If
Next r

Application.ScreenUpdating = False

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Am I missing something... Why don't you just add it at the bottom of the code between:

VBA Code:
Next r

and before

VBA Code:
Application.ScreenUdating = False

Two other things: First, you have your Application.ScreenUpdating reversed... "False" should be at the start of the code and "True" should be at the bottom of the code. Second, (and opinions vary on this) but it could not hurt to set Application.ScreenUpdating to "True" in the Else portion of the code before the
VBA Code:
 Exit Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,701
Messages
6,126,311
Members
449,308
Latest member
Ronaldj

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