0

I need help looping through a given range followed by an if statement. My Range is:

| A    | B     | C    |
-----------------------
|TPA   | C:\   | 1.doc|

|TPA   | C:\   | 2.doc|

|LAX   | D:\   | 3.doc|

I want to loop through A1:C3 and if Column A1:A3 = "TPA" Then take the data of B1 and C1.

Dim test1 As Variant
Dim cell As Range
Dim cell1 As Range
cell = Worksheets("Sheet2").Range ("A1:C3")
cell1 = Worksheets("Sheet2").Range ("A1:A3")
For Each cell1 in cell
If test1 = "TPA" Then 
'MsgBox B1 and C1 But I need to MsgBox B2 and C2 as well
End If
Next

Ultimately, I need to msgbox B1 + C1, and B2 + C2.

1 Answer 1

1
Dim test1 As String, c As Range, myRng As Range
Dim Result as string

set myRng = Worksheets("Sheet2").Range("A1:A3")
For Each c in myRng
    If test1 = "TPA" Then 
        Result = Result & c & c.offset(0,1) & vbCrLf
    End If
Next c
MsgBox Result
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.