アプリ版:「スタンプのみでお礼する」機能のリリースについて

いつもお世話になっております。

遣りたいこと
1.A列にあってB列になのものをC列
2.B列にあってA列にないものD列

結果
A列 B列 C列 D列  があります。
1   3  4  1
2   4  5  2
3   5  6
    6

下記のコードは検索してためしたものです。
その中で
ここの部分がわかりません。

わかりやすいコーどおしえてくれませんでしょうか

'A列にありB列にないデータを作成
row2 = 2

For Each key In dicA
sh.Cells(row2, 4).Value = key
row2 = row2 + 1
Next




Public Sub データ比較()
Dim row As Long
Dim row2 As Long
Dim dicA As Object '連想配列
Dim key As Variant
Dim sh As Worksheet
Dim time1 As Variant
Dim time2 As Variant
Dim maxrow1 As Long
Dim maxrow2 As Long
time1 = Time
Set dicA = CreateObject("Scripting.Dictionary") ' 連想配列の定義
Set sh = ActiveSheet
maxrow1 = sh.Cells(Rows.Count, 1).End(xlUp).row ' A列最終行を求める
maxrow2 = sh.Cells(Rows.Count, 2).End(xlUp).row ' B列最終行を求める

'A列の連想配列を作成


For row = 2 To maxrow1
key = sh.Cells(row, 1).Value
dicA(key) = row
Next


row2 = 2
For row = 2 To maxrow2
key = sh.Cells(row, 2).Value

If dicA.Exists(key) = True Then
dicA.Remove (key)
Else
sh.Cells(row2, 3).Value = key
row2 = row2 + 1
End If
Next

'A列にありB列にないデータを作成
row2 = 2

For Each key In dicA
sh.Cells(row2, 4).Value = key
row2 = row2 + 1
Next
time2 = Time
MsgBox ("処理完了 所要時間(秒)=" & Second(time2 - time1))
End Sub

A 回答 (1件)

やりたい事と結果が逆に思えるのですが。



Sub megu()
Dim i As Long
Dim n1 As Long
Dim n2 As Long

i = 1

Do Until Cells(i, 1).Value = "" And Cells(i, 2).Value = ""

With WorksheetFunction
If .CountIf(Range("B:B"), Cells(i, 1).Value) = 0 Then
n1 = n1 + 1
Cells(n1, 3).Value = Cells(i, 1).Value
End If

If .CountIf(Range("A:A"), Cells(i, 2).Value) = 0 Then
n2 = n2 + 1
Cells(n2, 4).Value = Cells(i, 2).Value
End If

End With
i = i + 1
Loop

End Sub
「VBA A列にありB列にないものまた逆」の回答画像1
    • good
    • 0
この回答へのお礼

めぐみん様
お久しぶりです
東西線です。パスワードわすれて
こういう結果となりました。
また、よろしくお願いいたします。
なんか安心しました。
嬉しいです

お礼日時:2020/10/13 19:39

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています


このQ&Aを見た人がよく見るQ&A