I'm trying to copy certain values of column to another sheet, but it's not working.
The code I am using is:
Worksheets("Report").Range(".Cells(x, 1)", ".Cells(x, 2)", ".Cells(x, 4)", ".Cells(x, 6)", ".Cells(x, 9):.Cells(x, 13)").Copy
You are using Range
wrong in two ways:
1) Range
has only one or two arguments. The usage is either
Range(someAddress)
where someAddress
is a String like "A1"
, "A1:B2
or even unions like "A1:B2,C3"
or
Range(startCell, endCell)
where startCell
and endCell
are the first and last cells of the range. They can be supplied either by address ( "A1"
) or by range object ( Cells(1,1)
).
Note that you can also pass ranges with multiple cells but I am not completely sure how it acts then.
2) You are putting your arguments in quotes, making them strings. That means that you don't pass a cell reference to Range
but the string ".Cells(x, 1)"
(not even x is replaced).
Now to create a range from multiple cells you can use Union
Union(.Cells(x, 1), .Cells(x, 2), ... )
or create an address string using the cells addresses
.Range(.Cells(x, 1).Address & "," & .Cells(x, 2).Address & "," & ...)
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.