0
votes

Sheet saskaita faktura Sheet darbinis

hopping to find help here. Can't get data from one sheet to another using conditions. My question: I will use example : if sheet1 cell d22 = sheet2 column B cells 3(4;5;6;..), then sheet1 cell P3 data copy and paste to sheet2 column C cells 3(4;5;6;..)

this should happen if i click button.

Thank you in advance. Darius

Adding code:

Sub bandymas()

If Sheets("Sàskaita-Faktûra").Range("d22") = Sheets("Darbinis").Range("D:D") Then
Sheets("Sàskaita-Faktûra").Range("P3").Copy
Sheets("Darbinis").Range ("O:O")
PasteSpecial Paste:=xlPaste, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    End If

End Sub 
2
yoou can format your code : select then ctrl +kuser3131905
now i put data by hand and simple if statement formulas to paste in all cells that match the criteria, with macro I'm new in the field.Darius B.
ok, you need test cells : cells(y,x)=, or range("D22") = , then you need a loop : for each c in range("A1:A20") if range etc.user3131905
Please post your VBA code where you are trying this so that we can help fix it.Rodger
@Rodger, the code is added in the question. Thanks for responding.Darius B.

2 Answers

0
votes

P is the source, o is destination, you can adjust

Sub bandymas()
LastRow = Sheets("Darbinis").Cells(Sheets("Darbinis").Rows.Count, "D").End(xlUp).Row
dim i 
i=0
for each c in Sheets("Darbinis").Range("D1:D" & lastRow)
    i=i+1
    If Sheets("Sàskaita-Faktûra").Range("d22") = c Then
       Sheets("Darbinis").Range("O" & i) = Sheets("Sàskaita-Faktûra").Range("P3").value  
    endif
next
End Sub 
0
votes

I found a solution, code looks:

Private Sub CommandButton2_Click()

Range("P3").Select
    Selection.Copy
    Range("P5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

lastrow = Sheets("Darbinis").Cells(Sheets("Darbinis").Rows.Count, "D").End(xlUp).Row
Dim i
i = 0
For Each c In Sheets("Darbinis").Range("D1:D" & lastrow)
    i = i + 1
        If Sheets("Sàskaita-Faktûra").Range("d22") = c Then
       Sheets("Darbinis").Range("O" & i) = Sheets("Sàskaita-Faktûra").Range("P5").Value
    End If
Next
End Sub

then it work as it suposed.