Copy specific columns for particular row (not entire row) into another sheet - Excel Macro

∥☆過路亽.° 提交于 2019-12-11 23:32:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!