Add this to current Macro?

Bret1

Board Regular
Joined
Jun 14, 2013
Messages
199
Hi, Can you help me add the following to the end of the code below? Note, the code below has a "stopping" point, and an "ending" point. I only want to run the following after the below code completes and ends.....
After completing the code, do this....
Copy ("R17:S17") and paste down (“R:S”) until “V” is has 3 blanks in a row (this is end of data on sheet).
Then, if there is any text in (“A”) greater than row A14, then Selection.ClearContents on ("R:S") on that row, and the row below it.
Example: If ("A15") has any text, then Selection.ClearContents of R15, S15, R16, S16 ---- (R:S is cleared on the same row as "A" and on one row GREATER than that row).
Thanks!

Below is the current code I'm running...
Code:
Sub Macro1()

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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Instead of trying to run everything from one macro, try making separate routines then have a single command to them all.
as an example this is my "commanding" routine:

VBA Code:
Sub run_all()

    'Runs all macros in given order at button push
    'Saves, sends and closes all workbooks
    '
   
    Application.ScreenUpdating = False
   
    Workbooks.Open Filename:=("J:\\Quality\07 Reports\04 Customer Report\PPM Log.xlsx")
   
    run_test
      
    Info_transfer
   
    Save_ActSht_as_Pdf
   
    Pdf_Shifts
   
    Email_Shifts
   
    Email_Shift_Weekly
      
    SAVE_WORKBOOKS
   
    Application.ScreenUpdating = True
   
End Sub

this way you can play with a "record macro" option to get the additional steps without upsetting your current macro.

I know this is not an answer, but hopefully a useful bit of guidance.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,600
Members
449,038
Latest member
Arbind kumar

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