Sub 条件()
Dim bk1, bk2 As Workbook
Dim sh1, sh2 As Worksheet
Dim Keyval, keyval2 As String
Dim i, s, x, y, z As Long
Dim str As String, del As String
Set bk1 = Workbooks("A")
Set bk2 = Workbooks("B")
Set sh1 = bk1.Worksheets("情報")
Set sh2 = bk2.Worksheets("結果")
On Error Resume Next
R1 = sh1.Cells(Rows.Count, "A").End(xlUp).Row
R2 = sh2.Cells(Rows.Count, "A").End(xlUp).Row
C1 = sh1.Range("A1").End(xlToRight).Column
C2 = sh2.Range("A1").End(xlToRight).Column
For i = 2 To R1
For s = 2 To R2
For x = 17 To C1
For y = 3 To C2
If sh1.Cells(1, x) = sh2.Cells(s, 2) And sh1.Cells(i, 1) = sh2.Cells(1, y) Then
sh2.Cells(s, y) = sh1.Cells(i, x)
End If
Next y
Next x
Next s
Next i
end sub
1Sub 条件1()2Dim bk1 As Workbook, bk2 As Workbook
3Set bk1 = ThisWorkbook 'Workbooks("A")4Set bk2 = ThisWorkbook 'Workbooks("B")56'表範囲取得7Dim rg1 As Range, rg2 As Range
8Set rg1 = bk1.Worksheets("情報").Range("A1").CurrentRegion
9Set rg2 = bk2.Worksheets("結果").Range("A1").CurrentRegion
10' On Error Resume Next1112Dim a1(), a2()13 a1 = rg1.Value
14 a2 = rg2.Value
1516Dim i AsLong, s AsLong, x AsLong, y AsLong, z AsLong17For i =2To UBound(a1,1)18For s =2To UBound(a2,1)19For x =2To UBound(a1,2)20For y =2To UBound(a2,2)21If a1(1, x)= a2(s,1)And a1(i,1)= a2(1, y)Then22 a2(s, y)= a1(i, x)23EndIf24Next y
25Next x
26Next s
27Next i
2829 rg2.Value = a2
30EndSub
なんども済みません。
例えば処理をしたいリストが空白行を一行はさみブロックとしてある場合、
Range("A1").の部分を変数として処理することは可能でしょうか。
以下のようなふうに目印を起点に処理をするようにしたいのですがうまくいきません。
可能でしたらご教示のほどよろしくお願いいたします。
Sub 条件1()
Dim bk1 As Workbook, bk2 As Workbook
Set bk1 = ThisWorkbook 'Workbooks("A")
Set bk2 = ThisWorkbook 'Workbooks("B")
Dim R2 As Long
R2 = bk2.Worksheets("結果").Cells(Rows.Count, "A").End(xlUp).Row
Dim b As Long
For b = 2 To R2
Dim key As Variant
'表範囲取得
Dim rg1 As Range, rg2 As Range
Set rg1 = bk1.Worksheets("情報").Range("A1").CurrentRegion
Set key = bk2.Worksheets("結果").Cells(b, 1).Find(what:="目印").Address
Set rg2 = key.CurrentRegion
' On Error Resume Next
Dim a1(), a2()
a1 = rg1.Value
a2 = rg2.Value
Dim i As Long, s As Long, x As Long, y As Long, z As Long
For i = 2 To UBound(a1, 1)
For s = 2 To UBound(a2, 1)
For x = 2 To UBound(a1, 2)
For y = 2 To UBound(a2, 2)
If a1(1, x) = a2(s, 1) And a1(i, 1) = a2(1, y) Then
a2(s, y) = a1(i, x)
End If
Next y
Next x
Next s
Next i
Next b
rg2.Value = a2
End Sub