复制 - 从多个行粘贴单元格值
Copy - paste cell value from multiply rows
我有一个问题。
我有多个行。每行列中的值很少。
我需要一个宏来让我选择任何行以将值从一列转移到另一列。
例如。
我有 5 到 23 行。我在每一行中都有 H、K、N、Q、T 列的值。
有一次我需要将第 6 行和过去的所有值剪切到 W、Z 列...,
其他时候我需要对第 15 行执行此操作。
是否有一些宏可以让我写下行号和 运行 仅用于该行的宏?或类似的东西?
我不擅长这个..
请帮忙。
谢谢大家
下面的怎么样,它会提示用户输入一个数字,然后它会在第 1 行查找那个数字,如果找到它就会将该列复制到 W 和 Z 列:
Sub foo()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
'declare and set your worksheet, amend as required
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'get the last row with data on Column A
start:
x = InputBox("Enter a Column Number to copy to column W & Z", "Copy Column") 'get number from user
If IsNumeric(x) Then 'make sure input was number
Set foundcolumn = ws.Range("1:1").Find(What:=x) 'find number on row 1
If Not foundcolumn Is Nothing Then 'if found
ws.Range(ws.Cells(5, foundcolumn.Column), ws.Cells(LastRow, foundcolumn.Column)).Copy 'copy from row 5 to last on given column
ws.Range("W5").PasteSpecial xlPasteValues 'paste in W5
ws.Range("Z5").PasteSpecial xlPasteValues 'paste in Z5
End If
Else
MsgBox "Please enter a number as in the first row"
GoTo start:
End If
End Sub
我有一个问题。 我有多个行。每行列中的值很少。
我需要一个宏来让我选择任何行以将值从一列转移到另一列。
例如。 我有 5 到 23 行。我在每一行中都有 H、K、N、Q、T 列的值。 有一次我需要将第 6 行和过去的所有值剪切到 W、Z 列..., 其他时候我需要对第 15 行执行此操作。
是否有一些宏可以让我写下行号和 运行 仅用于该行的宏?或类似的东西?
我不擅长这个.. 请帮忙。
谢谢大家
下面的怎么样,它会提示用户输入一个数字,然后它会在第 1 行查找那个数字,如果找到它就会将该列复制到 W 和 Z 列:
Sub foo()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
'declare and set your worksheet, amend as required
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'get the last row with data on Column A
start:
x = InputBox("Enter a Column Number to copy to column W & Z", "Copy Column") 'get number from user
If IsNumeric(x) Then 'make sure input was number
Set foundcolumn = ws.Range("1:1").Find(What:=x) 'find number on row 1
If Not foundcolumn Is Nothing Then 'if found
ws.Range(ws.Cells(5, foundcolumn.Column), ws.Cells(LastRow, foundcolumn.Column)).Copy 'copy from row 5 to last on given column
ws.Range("W5").PasteSpecial xlPasteValues 'paste in W5
ws.Range("Z5").PasteSpecial xlPasteValues 'paste in Z5
End If
Else
MsgBox "Please enter a number as in the first row"
GoTo start:
End If
End Sub