Benjamin Hoover
Benjamin Hoover

Reputation: 1

Taking multiple cells and using their info to create another cell

Right now I am trying to use the info from three different cells in a certain row to autofill another cell with the information I want. Its been awhile since I have used VBA and I don't quite know why I am getting "Object defined error". Here is my code and if you could help point me in the right direction I'd appreciate it.

Sub Conduit()

Sheets("Sheet4").Select

Dim celltxt As String
Dim celltxt2 As String
Dim celltxt3 As String
Dim i As Integer

i = 3

Do While Cells(i, 3).Value <> ""

    celltxt = ActiveSheet.Range("Bi").Text
    celltxt2 = ActiveSheet.Range("Fi").Text
    celltxt3 = ActiveSheet.Range("Di").Text

    If InStr(3, celltxt, "RMS") And InStr(3, celltxt2, "XHHW-2") And InStr(3, celltxt3, "1/C") Then
        [Ai].Value = "2"

    Else
        [Ai].Value = "999999"

    End If
    i = i + 1
Loop


End Sub

Upvotes: 0

Views: 18

Answers (1)

cyboashu
cyboashu

Reputation: 10433

This line celltxt = ActiveSheet.Range("Bi").Text is incorrect.

Try

celltxt = ActiveSheet.cells(i,2).Text

Same for Ai. You just can't intvar in string and expect it to be correct.

Upvotes: 2

Related Questions