2017-07-13 20 views
0

COUNTIF式に基づいていくつかの行を追加する必要があるマクロを作成中です。VBAを使用してセル内の特定の数値に基づいて行を追加します。

=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

あなたの指示はまだ説明できませんので、あまりにも助けてはいけません。私たちはコメントで議論し、私は私の答えを改善するつもりです。

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 
+0

操作の例を教えてください。 (たとえば、数式はセルA3にあり、destShtのセルA5に入る必要があります。次に、数式の値に基づいて行6の後にx行をdestShtに挿入します) – takanuva15

関連する問題