Zdeněk Bužga
Zdeněk Bužga

Reputation: 17

Increase number of column and write into selected cell

Good day,

I need help with a little problem. I have a macro which compares cell with range of cells. If the equal cell is not found, it will add the cell at the end of the range. My problem is with equal cell. If it finds it, I need to add 3 to column index and write "X" into this cell.

I have solution for unequal cell but i dont know how to increase column index and write into the cell.

I have this so far:

Sub Compare()
Dim i As Integer

    'Comparing cell is from another workbook
    Selection.Copy
    Windows("zzz.xlsm").Activate
    Range("A2").Select
    ActiveSheet.Paste

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

    Set FirstRange = Range("C" & i)

            If FirstRange.Value = Cells(2, 1).Value Then
            MsgBox "Found"
            Exit Do
            End If
        i = i + 1
    Loop
    If MsgBox = True Then
    'Missing code

    Else

    Range("A2").Select
    Selection.Copy
    ActiveSheet.Range("E" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveSheet.Paste

    End If

End Sub

I will appreciate any advice. Thank you for your time.

Upvotes: 0

Views: 49

Answers (1)

psychicebola
psychicebola

Reputation: 949

Sub Compare()
Dim i As Integer

    'Comparing cell is from another workbook
    Selection.Copy
    Windows("zzz.xlsm").Activate
    Range("A2").Select
    ActiveSheet.Paste

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

    Set FirstRange = Range("C" & i)

            If FirstRange.Value = Cells(2, 1).Value Then
            MsgBox "Found"
            Exit Do
            End If
        i = i + 1
    Loop
    If MsgBox = True Then

    Cells(i, 6) = "X" 'used to be Missing code
    Else

    Range("A2").Select
    Selection.Copy
    ActiveSheet.Range("E" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveSheet.Paste

    End If

End Sub

Upvotes: 2

Related Questions