does anyone has a clue how I can solve the following. I have a table in sheet 1 which I want to copy to sheet 2. However, copying will only take place for those cells in sheet1 for which column 3 row 11 to 32 are not empty. If say C11 is not empty, C11 will be copied together E11,F11,H11,I11 and J11. Then the code checks if C12 is filled and does the same and so on.
The copied cells are placed in sheet2 starting row and column 15. I have the following code which works very well. However it copies the formulas which obviously make no sense in sheet2, hence, values are nonsense:
Private Sub CommandButton1_Click()
Dim i As Integer
Dim a As Integer
a = 15
For i = 11 To 32
If Worksheets(1).Cells(i, 3) <> "" Then
Worksheets(1).Cells(i, 3).Copy Worksheets(2).Cells(a, 15)
Worksheets(1).Cells(i, 5).Copy Worksheets(2).Cells(a, 17)
Worksheets(1).Cells(i, 6).Copy Worksheets(2).Cells(a, 18)
Worksheets(1).Cells(i, 7).Copy Worksheets(2).Cells(a, 19)
Worksheets(1).Cells(i, 8).Copy Worksheets(2).Cells(a, 20)
Worksheets(1).Cells(i, 9).Copy Worksheets(2).Cells(a, 21)
a = a + 1
End If
Next i
How can I adjust the code in order to copy only the values?
Thank you very much for any support.
.Cells(y, x)
represents aRange
in VBA, andRange
has a.PasteSpecial
method. (Here's an MSDN link: msdn.microsoft.com/en-us/library/office/…) The option you're probably looking for here isxlPasteValues
– Dan Wagner