My Excel Sheet format is similar to this
Name code1 Name Code2 Name Number Input1 Input2
AB XY GSABPEXY1 110 BA BC
BC BA GSBCPEBA1 120
CD CA GSCDPECA1 13
DC DA GSDCPEDA3 140
BC BA GSBCPEBA3 15
Question:
- I want to obtain the values in the Name column by matching the inputs as in Input1 AND Input2.
- I need these matched values to be pasted in another sheet's predefined specific row and columns cells
- Using excel function countifs i am counting the number of rows having same repeating values in the Column A (name code1) and B (name code2) e.g. in above BC and BA which gives a count of 2.
- I would like to use this value (mentioned in #3) for the loop iteration
I got this code which looks very close but it lacks two things ABC is predefined in INSTR function and it doesn't have the AND operator - i do not know how to do it. I am very new to VBA so please pardon me if I am missing something simple and/or providing less info.
Code:
Sub Hostname()
Dim K As Long, r As Range, v As Variant
K = 1
Dim w1 As Worksheet, w2 As Worksheet
Set w1 = Sheets("Sheet2")
Set w2 = Sheets("Sheet3")
w1.Activate
For Each r In Intersect(Range("A:A"), ActiveSheet.UsedRange)
v = r.Value
If InStr(v, "ABC") > 0 Then
r.Copy w2.Cells(K, 1)
K = K + 1
End If
Next r
End Sub
Input1&Input2
and do a lookup on that? You wouldn't need any vba at all to do a lookup that way. – yu_ominae Jul 31 '14 at 5:12