0

複数の Excel シートのデータをマスター シートの 1 つの列に更新する方法に問題があります。新しい行を入力するたびに、マスター シートで自動的に更新されるようにします。値は id であるため、複数のワークシートで一意です。例えば:

Excel シート 1:

ID
---
1
2
3
4
5

Excel シート 2:

ID
---
12
23
34
41
53

Excel シート 3:

ID
---
123
215
324
445
562

マスター Excel シート:

ID
---
1
2
3
4
5
12
23
34
41
53
123
215
324
445
562

6 (ワークシート 1) のような新しい値を入力するたびに、マスター シートに更新されます。

それをしてもいいですか?マクロを使用する必要がありますか? ありがとう。

コードを SheetChange() で更新します


      With DataEntrySheet
         
         '** Set variables for using the Find method in a loop
        Set loopRng = DataEntrySheet.Columns(1)
        Set lookRng = MasterSheet.Columns(2)
         
         '** Set the range which will be used to write data if found
        Set OldLastCell = DoNotEditSheet.Range( _
        "C65536").End(xlUp).Offset(1)
         
         '** Start the Find loop
        For Each iCel In loopRng
             
             '** Using the Find method to find the cell value.
            Set foundRng = lookRng.Find(iCel.Value, lookRng.Cells(1), _
            xlValues, xlWhole, MatchCase:=True)
             
             '** Test if the variable 'foundRng' is Nothing.  If the value
             '   was not found, the variable will be Nothing, or else it
             '   will be the Range Object of that (first) found value.
            If foundRng Is Nothing Then
                 
                 '** Use the two ranges to transfer data (faster than Copy/Paste).
                OldLastCell.Value = iCel.Value
                OldLastCell.Offset(, -1).Value = iCel.Offset(, -1).Value
                OldLastCell.Offset(, 2).Value = iCel.Offset(, 1).Value
                OldLastCell.Offset(, 5).Value = iCel.Offset(, 2).Value
                OldLastCell.Offset(, 10).Value = iCel.Offset(, 3).Value
                 
                 '** Reset the variable to be one row below where we wrote the
                 '   data to.  This will keep the data organized by rows.
                Set OldLastCell = OldLastCell.Offset(1)
                 
            End If
             
             '** This MUST be set to Nothing before the next iteration.  If not,
             '   and a match is not found (following a good find) then you may
             '   have mismatched iterations with false results.
            Set foundRng = Nothing
        Next iCel
    End With
End Sub
4

1 に答える 1

0

イベントを使用しSheetChange()てマスター ワークシートを更新できますが、これによりデータ入力が非常に遅くなる可能性があります。

イベントは、SheetChange誰かがデータを入力して別のセルに移動するたびにコードを実行します。理想的には、データセット内のすべての列が完了したときにのみ、新しいデータを確認する必要があります。

新しい行の入力が完了し、マスター シートに入力する準備ができたときに押すことができるボタンを使用することをお勧めします。Web には、一致しない行を新しいシートに追加するコード サンプルが多数あります。

于 2012-07-26T20:34:15.037 に答える