根据列标题将单元格粘贴到特定的行中

我不是程序员,但会感谢一些帮助!

我正在尝试使用一系列单元格,并将它们粘贴到电子表格的另一部分,但是放在我想要的正确列中(该列稍后将更改,这就是为什么我需要它确定要将单元格粘贴到右侧的列行)

例如,将单元格(A2:A10)粘贴到“TTM”列中D4:D12 …,在那里我将文本TTM放入D1 …之后,TTM可能变为E1,在这种情况下,A2:A10细胞需要移动到E4:E12 …

非常感谢!

下面的函数可以用来做你想要的。 你需要解释什么会触发这个代码,如果你想search除了“活动表”

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