Looping through rows / columns and checking values to determine what value to assign to new column

StackOverflow https://stackoverflow.com/questions/22258720

  •  11-06-2023
  •  | 
  •  

Question

I've spent half day or so over this week learning vba, and building up this macro. After much research, mostly done on stackoverflow - this is what I have so far. I keep getting sub or function not defined when it compiles. It then highlights the world cell portion of the cell (i,"T").

I could use record macro and autofill a very nested series of ifs to get the proper result, but I wanted to try learning a bit of vba code. I know formulas, but limited vba, so I'm semi-dependent on the evaluate function. Thanks in advance for any help. I commented my logic in each section of code.

Sub GetCost()

GetCost Macro

Range("A2").Select
Selection.End(xlDown).Select

Dim X As Integer
X = Active.cell.Value + 1
'determines last row of imported data

For i = 2 To X
    'rows 2 to x, x being the highest active row imported, ignoring header (row 1)

    For J = 2 To 11
        'columns from 2 up to 11 are evaluated

        If Evaluate("iserror(Match(""cell(i, j).value"", Z:Z, 0), 2, 0") = False Then
            'check to see if cell(i,j) value exists in column Z

            If Evaluate("Index(Z:AA,Match(""cell(i, j).value"", Z:Z, 0), 2, ") = "N" Then
                'check to see that

                If Evaluate("isblank(""cell(i, j + 1)"")") = True Then
                    Set cell(i, "V").Value = cell(i, "T").Value
                    Exit For
                    'sets cost of parent item/subassembly to its current standard cost

                    Else: Set cell(i, "V").Value = 0
                    'if is false; parent item is purchased in its entirety and the current item belongs to parent item
                    'Sets value to 0, because the cost is inclusive of parent item
                    Exit For

                End If

            ElseIf J = 11 Then
            Set cell(i, "V").Value = cell(i, "T").Value
            'if no items match the lookup range, then current item is not an assembly or built inhouse, use current cost

            End If
        End If
    Next J
Next i


EndSub
Was it helpful?

Solution

Use cells instead of cell and drop the set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top