我录制了以下宏,然后编辑了代码以包含条件,但代码不能正常工作。当我删除第二个IF参数时,数据将被复制到distination表中的所有列中。我的目标是仅在列标题中的日期匹配时才复制数据。基本上我在工作表"每日输入表格"在一个简单的标签中,我希望将其复制到"每日现金流"工作表(具有多个列)仅当特定列标题中的日期与"每日输入表单中的日期匹配时#34;表...(这只是公式"今天()"。
我知道有一种更简单的方式来编写代码,但我是VBA的一个新手,所以感谢您能帮助我。
由于
Sub RangeCopy1()
'
' RangeCopy1 Macro
Dim lRow As Range, Cell As Object
Set lRow = Sheets("Daily Cash Flow").Range("E13:AV13")
For Each Cell In lRow
If Cell.Value = "YES" Then
Sheets("Daily Input Form").Select
Range("D7:D12").Select
Selection.Copy
Sheets("Daily Cash Flow").Select
Range("E36:AV36").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Daily Input Form").Select
Range("D15:D25").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Daily Cash Flow").Select
Range("E43:AV43").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Daily Input Form").Select
Range("D28:D34").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Daily Cash Flow").Select
Range("E56:AV56").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Daily Input Form").Select
Range("H7:H23").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Daily Cash Flow").Select
Range("E68:AV68").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Daily Input Form").Select
Range("H26:H63").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Daily Cash Flow").Select
Range("E86:AV86").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Daily Input Form").Select
Range("H66:H86").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Daily Cash Flow").Select
Range("E125:AV125").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
If Cell.Value = "" Then
Exit Sub
End If
Next
End Sub