我想知道如何从这样的工作表(“实际请求”)中复制数据:
Treaty: Property per risk
Treaty currency: EUR
Line of business of the risk: Property
New / Renewal: New
Insured Company /Name of risk: MNM Company
Occupancy / risk details: The risk is ...
到另一个工作表(“历史请求”),如下所示:
Treaty Treaty Currency Line of business New / Renewal Insured Company
我必须通过单击按钮来传输“历史请求”中的数据。另外,当我在“实际请求”工作表上插入其他信息时,我想将此新信息放在下一行(将现有信息保留在“历史请求”中)。 我在下面找到了代码,但是有一个问题,因为它会覆盖“历史请求”中的现有信息
希望我很清楚。 期待你的回复。 谢谢。
Sub TransferToHistory()
'
' TransferToHistory Macro
'
'
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets("Actual Request").Select
Range("B21").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 3).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B5").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 4).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B6").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 5).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B7").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 6).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B8").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 7).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B9").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 8).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B10").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 9).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B13").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 10).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("C13").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 11).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B14").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 12).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B17").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 13).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B18").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 14).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B19").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 15).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("B20").Select
Selection.Copy
Sheets("Historical Requests").Select
Cells(Cells(1, 1).Value, 16).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Actual Request").Select
Range("A1").Select
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
您可以在粘贴时复制数据并转置数据。下面是执行此操作的代码。
Sub Macro4()
Application.CutCopyMode = False
Sheets("Actual Request").Range("B24", Range("B24").End(xlDown)).Copy
Sheets("Historical Requests").Range("A1").End(xlDown).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
End Sub
注意:我尚不确定“ 实际请求”表中的数据如何。因此,这可能不会给您预期的结果。