Macro to Copy and Paste Values 3 rows before text "Total"

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have text Total" in Col A

I have written code to copy & paste values in C2:D & Last row (LR) F2:G & Last row

I need the formula to be amended so that the last row is 3 rows before "Total" in Col A

Your assistance is most appreciated


Code:
 Sub Range_ValueFormulas()
Dim lr As Long
 With Sheets("Cash Sales")
lr = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("C2:D" & lr).Copy
.Range("C2").PasteSpecial Paste:=xlPasteValues
.Range("F2:G" & lr).Copy
.Range("F2").PasteSpecial Paste:=xlPasteValues
.Application.CutCopyMode = False


  End With
  
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Untested.
VBA Code:
Sub Range_ValueFormulas()
Dim Fnd As Range, lr As Long
 With Sheets("Cash Sales")
Set Fnd = .Range("A:A").Find("Total", LookIn:=xlValues, lookat:=xlWhole)
If Not Fnd Is Nothing Then
    lr = Fnd.Row - 3
Else
    MsgBox "Can't find ""Total"" in column A - exiting  sub"
    Exit Sub
End If
.Range("C2:D" & lr).Copy
.Range("C2").PasteSpecial Paste:=xlPasteValues
.Range("F2:G" & lr).Copy
.Range("F2").PasteSpecial Paste:=xlPasteValues
.Application.CutCopyMode = False
  End With
End Sub
 
Upvote 0
Solution
Hi Joe

Thanks for the help. Code works perfectly
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,825
Members
449,096
Latest member
Erald

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