我想先检查一下,如果ActiveCell为空,那么:
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("Data").Range("A1:B1").Copy
ActiveCell.Offset(0, -1).PasteSpecial
Application.CutCopyMode = False
Application.DisplayAlerts = True
然后,如果ActiveCell不为空,我想:
我不知道如何将值从内存粘贴到ActiveCell。有提示吗?
这是我当前的代码:
Sub TimescheduleIndent1()
Dim KeepMeInMemory As String
If Intersect(ActiveCell, ThisWorkbook.Worksheets("Timeschedule").Range("B8:B90")) Is Nothing Then
Else
If ActiveCell = "" Then
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("Data").Range("A1:B1").Copy
ActiveCell.Offset(0, -1).PasteSpecial
Application.CutCopyMode = False
Application.DisplayAlerts = True
Else
Application.DisplayAlerts = False
ActiveCell = KeepMeInMemory
ThisWorkbook.Worksheets("Data").Range("A1:B1").Copy
ActiveCell.Offset(0, -1).PasteSpecial
ActiveCell.Offset(0, 0).PasteSpecial xlPasteValues ' Here should come value from memory *KeepMeInMemory*
Application.CutCopyMode = False
Application.DisplayAlerts = True
End If
End If
End Sub
整个代码仅适用于范围B8:B90
。如果ActiveCell不在范围内,则什么也不做。
答案 0 :(得分:0)
我认为这是因为您试图在此处存储ActiveCell值
ActiveCell = KeepMeInMemory
此操作试图将ActiveCell
设置为变量KeepMeInMemory
,该变量为空,因为您尚未为其分配任何内容。相反,您需要做的是。
KeepMeInMemory = ActiveCell.value
然后,如果您确实想为该变量设置单元格值,则需要像这样分配它。
ActiveCell.Offset(0, -1).value = KeepMeInMemory
我认为这就是您想要做的。