|
こんにちは。
Sub djj()
Dim TxSh As Worksheet, Cel As Range, Mat As Variant, ADC As Range
'ここにファイルA.txtを開くコードが書いてあるとして
'つまり、ファイルA.txtがアクティブ
Set TxSh = ActiveSheet
With Workbooks("bookA.xls")
For Each Cel In TxSh.Range("B1", TxSh.Range("B65536").End(xlUp))
Mat = Application.Match(Cel.Value, .Sheets("果物").Columns(1), 0)
If Not IsError(Mat) Then
.Sheets("果物").Cells(Mat, 2).Value = Cel.Offset(, 1).Value
Else
Mat = Application.Match(Cel.Value, .Sheets("野菜").Columns(1), 0)
If Not IsError(Mat) Then
.Sheets("野菜").Cells(Mat, 2).Value = Cel.Offset(, 1).Value
Else
Set ADC = .Sheets(Cel.Offset(, -1).Value).Range("A65536").End(xlUp).Offset(1)
ADC.Value = Cel.Value
ADC.Offset(, 1).Value = Cel.Offset(, 1).Value
End If
End If
Next
End With
Set TxSh = Nothing
Set ADC = Nothing
End Sub
|
|