+ Reply to Thread
Results 1 to 4 of 4

How to fill a cell with formula if condition fulfilled

Hybrid View

ruliansyah How to fill a cell with... 02-06-2013, 11:40 PM
Alf Re: How to fill a cell with... 02-07-2013, 03:18 AM
ruliansyah Re: How to fill a cell with... 02-07-2013, 03:25 AM
Alf Re: How to fill a cell with... 02-07-2013, 05:29 AM
  1. #1
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Question How to fill a cell with formula if condition fulfilled

    Hello masters,

    I need help, I need vba code to do this:
    If I enter value on column C1 and D1 then I would like column E1 automatically filled with formula like "=(C1*D1)-((C1*D1)*10%)" and so with the next row but only if i enter the value on c and d, if nothing entered then the formula is not needed.
    Please help me.

    Thank you

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,792

    Re: How to fill a cell with formula if condition fulfilled

    You could try a formula like this

    =IF(AND(C1<>0,D1<>0),(C1*D1)-(C1*D1)*0.1,"")
    Don't know what your decimal separators are "," or "." or if you use ";" or "," but I guess the later. Test if it works.

    Alf
    Last edited by Alf; 02-07-2013 at 03:21 AM. Reason: modify for negative values

  3. #3
    Registered User
    Join Date
    12-26-2012
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    38

    Re: How to fill a cell with formula if condition fulfilled

    thank you for your reply mr. Alf, I don't want to put the formula manually on the cell I want to use vba code to insert the formula and copy the validation from row above.
    would you please help me with that?

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,792

    Re: How to fill a cell with formula if condition fulfilled

    Well then you could try a macro like this.

    Sub WriteForm()
    
    Dim i As Integer
    
    For i = 1 To Range("C" & Rows.Count).End(xlUp).Row
    
    If Cells(i, 3) <> 0 And Cells(i, 4) <> 0 Then
        
        Range("E" & i).Formula = "=(C" & i & "*D" & i & ")-(C" & i & "*D" & i & ")* 0.1"
        
    End If
    
    Next
     
    End Sub
    Alf
    Last edited by Alf; 02-07-2013 at 06:26 AM. Reason: trimming formula

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1