2016-04-04 11 views
0

私は2つの範囲(両方2次元)を持っています。 R1(H1:M4)には、R2(A6:N15)のセルの可能な値のリストが含まれています。 R2は空白のセルを含むことがあります。 R2のセルがR1のセルと一致する場合、R1の一致した値の列(N1:N4)の最後のセルを出力します。私は、範囲H1を使用してい範囲内の値を検索し、別の範囲と比較します。それが存在する場合は、特定の値を与えます

IF(A6="", "Blank", 
    IFERROR(VLOOKUP(A6, $H$1:$N$4, 7,FALSE), 
    IFERROR(VLOOKUP(A6, $I$1:$N$4, 6,FALSE), 
     IFERROR(VLOOKUP(A6, $J$1:$N$4, 5,FALSE), 
     IFERROR(VLOOKUP(A6, $K$1:$N$4, 4,FALSE), 
      IFERROR(VLOOKUP(A6, $L$1:$N$4, 3,FALSE), 
      IFERROR(VLOOKUP(A6, $M$1:$N$4, 2,FALSE), 
       IFERROR(VLOOKUP(A6, $N$1:$N$4, 1,FALSE), "None")))))))) 

注:VLOOKUPためのN4

IはP6(IFERRORをネスト)に以下の式を使用しています。

これは私には解決策を与えていますが、私はより効率的な解決策が必要です。

+1

[。 Find](http://www.siddharthrout.com/2011/07/14/find-and-findnext-in-excel-vba/)? –

+0

おそらくそれはあなたが思っている解決策を与えるものではありません。これらのVLOOKUPはそれぞれ、H1:H4のG45のみを検索します。あなたはH ** Mから決して列Nからの値を返す**だけ**です。 – Jeeped

答えて

0

役立ちますか?

Sub Test() 
    Dim R1 As Variant, R2 As Variant, x As Variant, y As Variant 
    Set R1 = Range("H1:M4") 
    Set R2 = Range("A6:N15") 
    For Each x In R1 
     If x.Value = "" Then 
     GoTo skip 
     End If 

     For Each y In R2 
      If y.Value = "" Then 
       y.Offset(0, 16) = "Blank" 
      ElseIf x = y Then 
      y.Offset(0, 16) = x 
      End If 
     Next y 
skip: 
Next x 
End Sub 
+0

私はむしろGotoステートメントを使用したくないです。 –

0

次作品:

Sub FindMatches() 
    Dim R1 As Variant, R2 As Variant, x As Variant, y As Variant 
    Set R1 = Range("H1:M4") 
    Set R2 = Range("A6:N15") 
    For Each x In R1 
     If x.Value = "" Then 
     End If 
     For Each y In R2 
      If y.Value = "" Then 
       y.Offset(0, 16) = "Blank" 
      ElseIf x.value = y.value Then 
       y.Offset(0, 16) = x.Offset(0, 7 - x.Column) 
      End If 
     Next y 
     End If 
    Next x 
End Sub 
0

あなたはそれがにいいと思いR1とR2の両方を通じて

をループするよりもはるかに少ない反復を行い、この

Option Explicit 

Sub FindThem() 
Dim rng1 As Range, rng2 As Range, cell As Range 
Dim strng As String 
Dim i As Long, iRow As Long, nCol As Long 

Set rng1 = Range("H1:M4") 
Set rng2 = Range("A6:N15") 
nCol = rng1.Columns.Count 

For i = 1 To rng1.Rows.Count 
    strng = strng & Join(Application.Transpose(Application.Transpose(rng1.Rows(i))), "-") & "-" 
Next i 
strng = "-" & strng ' this is the string that collects all rng1 values 

For Each cell In rng2 
    i = InStr(strng, "-" & cell.Value & "-") 
    If i > 0 Then 
     iRow = Len(Left(strng, i + 1)) - Len(Replace(Left(strng, i + 1), "-", "")) ' count the "position" of the value in the string 
     cell.Offset(, 16) = rng1(Int(iRow/nCol) + IIf(iRow Mod nCol = 0, 0, 1), 7) 
    End If 
Next cell 
End Sub 

を試みることができますあなたが直面している問題は、最も速い、提供されたスピードであることを知る

もちろん、R1の値は一意でなければなりません。そうでなければ、R2で最初に出現する行(行ごと、列ごとに検索されます)はキャッチされます。

関連する問題