lundi 30 juillet 2018

Retrieve the value of the cell from the same row and opposite column if the conditions match in VBA

I'm currently working on an extract from a code for implementing a series of workbooks, that looks something like this:

Sub CopyData()
NewBook = ""
Path = ThisWorkbook.Path
Sheets("Staff").Select
For i = 2 To 100000
If Cells(i, 1).value = "" Then
    i = 100000
Exit For
End If
Name_file = Path & "\" & Sheets("Staff").Cells(i, 1).value & ".xls"
Sheets("TEMPLATE_TARGET").Select 

 Range("Vnt").value = Sheets("Staff").Cells(i, 5).value
If Range("Vnt").value = Worksheets("Sheet1").Range("G4:ED4").value And 
Worksheets("Sheet1").Range("G5:ED57").value <> 0 Then
 Range("Vtti").value = ????
Cells.Select
Selection.Copy

I need some help with defining the Vtti cell: If the cell defined Vnt is sharing any value from the range G4:ED4 in worksheet Sheet1 and if any of the cells under the matched cell in Sheet1 is not empty, then the value of the cell Vtti is equal to a data stored in a Sheet 1's column B cell, that is located on the same row as the filled cell.

Could you recommend a way how to define a logically proper IF..THEN..END IF statement for my case? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire