我正在编写一个宏,需要根据COUNTIF公式添加多行。
=COUNTIF(D2:D1000,">=1/1/2017")-COUNTIF(D2:D1000,">1/2/2018")
基本上,我希望能够将该公式放在我的目标表上,使用公式计算日期出现在我的源电子表格范围内的所有时间,返回计数并根据内容添加新行价值是。公式是准确的,它现在只是在错误的位置(它在源电子表格上,而不是目的地)。我有一些代码的开头,但我正在努力寻找下一步去实现我的目标。有人可以帮忙吗?
Sub Map_To_Import_Sheet()
Dim wbs As Workbook 'Source workbook
Dim wbd As Workbook 'Destination workbook already open
Dim ss As Worksheet 'Source worksheet
Dim ds As Worksheet 'Destination worksheet
Set wbd = ThisWorkbook
Set wbs = Workbooks.Open("S:\Accounts (New)\Management Information
(Analysis)\Phil Hanmore - Analysis\Neil Test\TimeSheet Templates\Copy of
MSI shifts 19th June - 25th June.xlsx")
Set ss = wbs.Worksheets(1)
Set ds = wbd.Worksheets("Import Sheet")
'Removes the data from the columns A through R in NHSP Import Template
ds.Range(ds.Range("A4:R18"),
ds.Range("A4:R18").End(xlDown)).ClearContents
'Counts the rows with data on the source spreadsheet and adds the
appropriate number to the destination (Import sheet)
ss.Activate
答案 0 :(得分:0)
您的说明尚无描述性,因此我无能为力。我们将在评论中进行讨论,并在我们开始时提高答案。
Sub Map_To_Import_Sheet()
Dim srcWb As Workbook 'Source workbook
Dim destWb As Workbook 'Destination workbook already open
Dim srcSht As Worksheet 'Source worksheet
Dim destSht As Worksheet 'Destination worksheet
Set destWb = ThisWorkbook
Set srcWb = Workbooks.Open("filepath")
Set srcSht = srcWb.Worksheets(1)
Set destSht = destWb.Worksheets("Import Sheet")
'Removes the data from the columns A through R in NHSP Import Template
'- Import Sheet
destSht.Range(destSht.Range("A4:R18"), destSht.Range("A4:R18").End(xlDown)).ClearContents
'Counts the rows with data on the source spreadsheet and adds the
'appropriate number to the destination (Import sheet)
Dim count As Integer
count = srcSht.Range("cell formula location").Value
srcSht.Range("cell formula location").Copy
destSht.Range("new cell formula location").PasteSpecial xlPasteFormulas
'MsgBox count 'prints out count
'explain your insert more please
End Sub