I'm trying to make a macro to check if column "A3" is empty" then copy cells "A3:K3" from sheet "Outros" then insert a line in "Docs" sheet after line number 2 then paste only values to A3:K3 "Docs"...
The major problem is copy and paste only values + insert line, the nearest formula that I reach was
Worksheets("Outros").Range("A3:K3").Copy Destination:=Worksheets("Docs").Range("A3:K3")
But with this I paste formulas not only values and it doesn't insert a line.
To shift a row down use:
Rows(3).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Before you copy/paste
To paste the values and not formulas use:
.PasteSpecial Paste:=xlPasteValues
Maybe this will help you to make your own code:
Sub test()
Dim rng_one As Range
Dim rng_two As Range
Set rng_one = Worksheets("Outros").Range("A3:K3")
Set rng_two = Worksheets("Docs").Range("A3:K3")
' check if range is empty
If Application.WorksheetFunction.CountA(rng_two) = 0 Then
' insert row above row 3
Worksheets("Docs").Rows("3:3").Insert Shift:=xlDown
' copy paste as values
rng_one.Copy
rng_two.PasteSpecial xlPasteValues
Excel.Application.CutCopyMode = False
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.