I have some VBA code that copys a range from one sheet and then pastes it to another at the first blank line. What it is copying are vlookup formulas so when it pastes it pastes all 0's, how would I go about getting it to paste what it copies as values so the results are retained?
Code:
Private Sub PasteChartDataQtyCompare()
'This step pastes the range of values to the chart data tab
Sheets(1).Range("A6:J22").Copy _
Destination:=Sheets("Chart Data").Cells(Sheets("Chart Data").Rows.Count, 1).End(xlUp).Offset(1, 0)
End Sub
Transfer the values directly bypassing the clipboard.
Private Sub PasteChartDataQtyCompare()
'This step pastes the range of values to the chart data tab
with workSheets(1).Range("A6:J22")
workSheets("Chart Data").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).resize(.rows.count,.columns.count) = .value
end with
End Sub
Use Range Method "Range.PasteSpecial xlPasteValue"
Example:
Sheets("Sheet1").Columns("A").Copy
Sheets("Sheet2").Columns("B").PasteSpecial xlPasteValues
You want to use
.PasteSpecial xlPasteValues
A similar question was answered in detail here: Excel VBA Copy Paste Values only( xlPasteValues )
Related
I have some VBA code that copys a range from one sheet and then pastes it to another at the first blank line. What it is copying are vlookup formulas so when it pastes it pastes all 0's, how would I go about getting it to paste what it copies as values so the results are retained?
Code:
Private Sub PasteChartDataQtyCompare()
'This step pastes the range of values to the chart data tab
Sheets(1).Range("A6:J22").Copy _
Destination:=Sheets("Chart Data").Cells(Sheets("Chart Data").Rows.Count, 1).End(xlUp).Offset(1, 0)
End Sub
Transfer the values directly bypassing the clipboard.
Private Sub PasteChartDataQtyCompare()
'This step pastes the range of values to the chart data tab
with workSheets(1).Range("A6:J22")
workSheets("Chart Data").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).resize(.rows.count,.columns.count) = .value
end with
End Sub
Use Range Method "Range.PasteSpecial xlPasteValue"
Example:
Sheets("Sheet1").Columns("A").Copy
Sheets("Sheet2").Columns("B").PasteSpecial xlPasteValues
You want to use
.PasteSpecial xlPasteValues
A similar question was answered in detail here: Excel VBA Copy Paste Values only( xlPasteValues )
it paste the value but not to the last rows in the sheet (List) the END(xlDown).offset(1) stop the
macros and make it crash, I get error 1004 object undefined.
Can someone help me better up this code>
Private Sub CommandButton2_Click()
Dim ws As Worksheet
Set ws = ActiveSheet
Worksheets("FORM").Range("B7").Copy
Worksheets("List").Range("B7").End(xlDown).Offset(1).PasteSpecial xlPasteValues
Worksheets("FORM").Range("D7").Copy
Worksheets("List").Range("C7").PasteSpecial xlPasteValues
Worksheets("FORM").Range("G7").Copy
Worksheets("List").Range("D7").PasteSpecial xlPasteValues
'second line in the same row'
Worksheets("FORM").Range("A8").Copy
Worksheets("List").Range("F7").PasteSpecial xlPasteValues
Worksheets("FORM").Range("E8").Copy
Worksheets("List").Range("G7").PasteSpecial xlPasteValues
Worksheets("FORM").Range("H8").Copy
Worksheets("List").Range("H7").PasteSpecial xlPasteValues
Worksheets("FORM").Range("K8").Copy
Worksheets("List").Range("I7").PasteSpecial xlPasteValues
End Sub
This is because you're using Worksheets("FORM") when you should be using Sheets("FORM")
Also, when you're using .Offset() you need to specify the row AND column numbers you want to ofset by - so .Offset(1,0) in your case I imagine.
If you make those changes, your code should work.
In a VBA Excel macro,
I copy rows from another sheet, select a different sheet, and try to find the next open cell before pasting them.
Range("A1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
The page has a first row of column titles, and find then passes over these to the very last row???
If dummy data
is put in the second row, or if there is data already present,
it works.
WHY is it doing this?
Range.End(xlDown) is equivalent to pressing Ctrl + ↓.
Test it on your own - if you only have a header in Row 1, then you'll jump to the last row in the Worksheet. If you have data below the header, you'll move to that row.
Use Range.End(xlUp) to find the next available row by moving up from the last row on the Worksheet - something like this:
With Sheet1
.Cells(.Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
standing your data layout, you can use:
Cells(WorksheetFunction.CountA(Columns(1)) + 1, 1).PasteSpecial Paste:=xlPasteValues
or, using explicit worksheet references (recommended):
With Worksheets("mySheetName")
.Cells(WorksheetFunction.CountA(.Columns(1)) + 1, 1).PasteSpecial Paste:=xlPasteValues
End With
I have a macro that is supposed to copy the format of a row and insert a new row with the same format.
Here is the macro code:
Sub Insertion_ligne_verrouillée()
'
' Insertion_ligne_verrouillée Macro
ActiveSheet.Unprotect
ActiveCell.Offset(-1, 0).EntireRow.Copy
Rows(ActiveCell.Row).Insert Shift:=xlDown
On Error Resume Next
Rows(ActiveCell.Row).SpecialCells(xlCellTypeConstants).ClearContents
ActiveSheet.Unprotect
'Application.CutCopyMode=False
End Sub
Now i am not the one that wrote the macro and honestly my VBA is quite rusty (also not that good in VBA either). The problem i am having is the user is using the macro by selecting a row and using ctrl+L.
It does copy and insert a row with the right format, however some rows afterward seem empty (all blank and no row number) so you have to select the row > right click > display, for it to display properly
Not sure what to look for
The following code makes a new row below the row you want to copy then copies the format of the row and paste into the new row.
Sub Insertion_ligne_verrouillée()
'Make a new row below active cell
ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown,
CopyOrigin:=xlFormatFromRightOrAbove
'Copy the active row
ActiveCell.EntireRow.Copy
'paste format into new row
ActiveCell.Offset(1).EntireRow.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End Sub
I need a simple twist to a common vba code that copy and paste columns/rows
What I am trying to do is copy the entire row in sheet 2 , transpose and then paste them into Column A , Sheet1. The first row in sheet1 has the headings so I have to paste them into A2 that extends to the whole column
Sub transpose2()
Sheets(2).Range("A1", Cells(Columns.Count, "A").End(xlRight)).Copy
Sheets(1).Range("A2").PasteSpecial transpose:=True
Range("A1").ClearOutline
End Sub
This doesn't seem to work.
Can anyone help me with this?
Thank you!
Sub transpose2()
With Sheets(2)
.Range(.Range("A1"), .Cells(1, .Columns.Count).End(xlToLeft)).Copy
End With
Sheets(1).Range("A2").PasteSpecial transpose:=True
Range("A1").ClearOutline 'which sheet?
End Sub