问题
I am trying to get a macro to copy rows dependent on certain criteria, in this case "FX Ccy Options", for a table of data using column M. I have manged to do this with the below code, but I don't want to copy the entire row (c.EntireRow.copy). Just for all the columns with data (C:X).
Sub Button2_Click()
Dim bottomL As Integer
bottomL = Sheets("DGM").Range("M" & Rows.Count).End(xlUp).Row: x = 1
Dim c As Range
For Each c In Sheets("DGM").Range("M1:M" & bottomL)
If c.Value = "FX Ccy Options" Then
c.EntireRow.Copy Worksheets("sheet2").Range("A" & x + 1)
x = x + 1
End If
Next c
End Sub
回答1:
c.EntireRow.Range("C1:X1").Copy
Here "C1:X1" is relative to the specificed row.
Similarly
someRectangularRange.Range("A1")
is the top-left cell in someRectangularRange
来源:https://stackoverflow.com/questions/36047959/copy-specific-columns-for-particular-row-not-entire-row-into-another-sheet-e