Search code examples
excelvba

Select and copy a cell to another sheet


If conditions in two columns are met this code is supposed to take a value from another sheet and paste it into the end of the row of the checked row to the source sheet.

For testing purpose, I tried to keep it at a specific range.

cell.Value is most likely wrong and the range is probably not working as I imagined. Also, it is probably not looping through the columns.

I have different cell possibilities to copy for different conditions and I suppose I can adjust them each depending on the conditions.

Sub Update()
Dim Column As Range
Sheets("Q485").Select
Set Column = Range.Select("AV:AW")
    If Column("AW") Is cell.Value("P") And Column("AV") Is cell.Value("V") Then
        Sheets("Support").Select
        Range("C9").Select
        Selection.Copy
        Sheets("Q485").Select
        Range("AY6358").Select
        Selection.Paste
'    Else 
'    Other conditions will be written below
    end if

End Sub

Solution

  • Sub MyMacroc ()
        Dim rng as range
        set rng = sheets("Source").range("A2:A7")
    
        For Each cel In rng.Cells
            with cel
                'condition -1 '
                if .offset(0,1)="P" and .Offset(0,2)="V" then
                    .offset(0,3) = Sheets("Extract").range("B2")
                ElseIF
                    'your second conition 
                end if
            end with
        next
    
    End sub