簡體   English   中英

根據列標題將單元格粘貼到特定行中

[英]Paste cells in specific row based on column header

我不是程序員,但希望獲得幫助!

我正在嘗試提取一系列單元格,然后將其粘貼到電子表格的另一部分中,但要粘貼到我想要的正確列中(此列稍后會更改,這就是為什么我希望它標識出將該單元格粘貼到右側的列的原因行)

例如,取單元格(A2:A10)並將其粘貼到“ TTM”列D4:D12 ...中,然后將文本TTM放入D1 ...之后,TTM可能會變成E1,在這種情況下,A2:A10單元格需要移動到E4:E12 ...

非常感謝!

以下功能可用於執行您想要的操作。 您需要說明什么會觸發此代碼,以及是否要搜索“有效工作表”以外的內容

Function Move_Cells()
Dim iCols   As Integer
Dim i       As Integer
Dim strKey  As String
Dim iNewCol As Integer

    strKey = "TTM"      ' Set this to whatever label you want to search row 1 for.
    iCols = ActiveSheet.UsedRange.Columns.Count         ' Get count of used columns

    For i = 1 To iCols              ' Find column containing 'TTM'
        If LCase(Cells(1, i).text) = LCase(strKey) Then     ' ignore case inCASE SoMeBody....
            iNewCol = i             ' Save col # containing search keyword
            Exit For
        End If
    Next i

    'ActiveSheet.Range("A2:A10").Copy        ' Where to copy from
    'ActiveSheet.Cells(2, iNewCol).PasteSpecial xlPasteValues        ' Paste into new location
    'Application.CutCopyMode = False

    ' Try the following instead of the previous copy/paste
    Range("A2:A10").Select
    Selection.Copy
    Cells(2, iNewCol).Select
    ActiveSheet.Paste

End Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM