Forum Discussion

KAM_Mumin's avatar
KAM_Mumin
Brass Contributor
Oct 22, 2022
Solved

MS EXCEL VBA IF Formula.

Hi Everyone!

I have a stock sheet with all models which I have already and now want to get some spcific models stock in a new sheet,,,

I use =SUMPRODUCT(([@[Model No]]=RefModelsT[Model No])*RefModelsT[Onhand])

to get the value, now i want to do it with VBA IF formula,,,  but when i use

Sub macro()

'

If range("NewT[@Model No]").value = range("RefModelsT[Model No]").value Then

What i want to do,,,, but error showing on the start of IF formula criteria ...

What i need to do if want to match this,, 

Please any of you have solution then please reply,,,

I attach below some screenshot and a attach for understanding,,,

😉

 

 

 

  • KAM_Mumin 

    Do you want to sum in VBA only with IF THEN ELSE END IF statement without using a standard sum formula (SUMIF, SUMIFS, SUMPRODUCT)? If so i can't help you unfortunately.

4 Replies

  • KAM_Mumin 

    Sub MyMacro()
    Dim Destws As Worksheet
    Dim lastrow As Long
    
    Set Destws = Worksheets("NewT")
    lastrow = Destws.Cells(Destws.Rows.Count, "A").End(xlUp).Row
        
        Destws.Range("C2:C" & lastrow).FormulaR1C1 = "=SUMPRODUCT(([@[Model No]]=RefModelsT[Model No])*RefModelsT[Onhand])"
    
    End Sub

    Maybe with these lines of code. In the attached file you can click the button in cell G2 to run the macro.

    • KAM_Mumin's avatar
      KAM_Mumin
      Brass Contributor
      Bro yours is ok,,, but I want to do it by VBA IF function,,,if you can then Please
      • OliverScheurich's avatar
        OliverScheurich
        Gold Contributor

        KAM_Mumin 

        Do you want to sum in VBA only with IF THEN ELSE END IF statement without using a standard sum formula (SUMIF, SUMIFS, SUMPRODUCT)? If so i can't help you unfortunately.

Resources