VBA Code for Getting Divisior

  • Hi Guys,


    I am new to VBA and trying to get below done through vba code.


    Column "A" has 1 to 100 numbers and in column "B", i want result if the number is divisor of 3 or if the number is divisor of 5 or both.
    I have done through formula as below
    =IF(AND(MOD(A2,3)=0,MOD(A2,5)=0),"3-5",IF(MOD(A2,3)=0,"3",IF(MOD(A2,5)=0,"5","")))


    Thanks

  • Re: VBA Code for Getting Divisior


    see this


    Code
    Sub findmod()
    Set myrange = Sheets("Sheet1").Range("A1", Range("A" & Rows.Count).End(xlUp))
    For Each cell In myrange
    If cell.Value Mod 3 = 0 Then cell.Offset(0, 1) = 3
    Next cell
    End Sub


    develop similar code for the other validations and then post back ur code for the benefit of everybody

  • Re: VBA Code for Getting Divisior


    Or maybe


    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: VBA Code for Getting Divisior


    Thanks pangolin.. exactly what I was looking for...
    Thanks KjBox.. I did not intend to put the formula to calculate.


    My Final Code.


  • Re: VBA Code for Getting Divisior


    Did you try my code? It does put the formula there but then immediately removes the formula and replaces it with the result of the formula as a value.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!