Results 1 to 5 of 5

Thread: New to Excel If statements

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    New to Excel If statements

    Hey all, I have an excel sheet that pulls data from a database.

    How can I get column C cells to have the formula =A<row number>-(B<row number>/10)

    IF A and C are not the same value, if they are...I want it to make the formula exclude the /10.
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: New to Excel If statements

    I'm not sure what you are really after here... you say that if A and C are the same, but as C is a calculation that involves A, the /10 will be irrelevant when they are equal (as it means that B is 0).

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    Re: New to Excel If statements

    Sorry, I meant if A AND B are not the same
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: New to Excel If statements

    In cell C2:
    Code:
    =If(A2=B2, A2-B2, A2-(B2/10)
    ..then copy & paste to the rest of C

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: New to Excel If statements

    Replace "Sheets1" with the name of the relevant sheet.

    Code:
    Option Explicit
    Sub Test()
    Dim I
    
    I = 1
    
    'loop to ensure that the formula is put in the cells till where
    'the data is in Column B
    Do While Len(Trim(Sheets("Sheets1").Range("B" & I).Value)) <> 0
        If Sheets("Sheets1").Range("A" & I).Value = _
        Sheets("Sheets1").Range("B" & I).Value Then
            'C = A - B if if A = B
            Sheets("Sheets1").Range("C" & I).Value = _
            Sheets("Sheets1").Range("A" & I).Value - _
            Sheets("Sheets1").Range("B" & I).Value
        Else
            'C = A - (B/10) if A<>B
            Sheets("Sheets1").Range("C" & I).Value = _
            Sheets("Sheets1").Range("A" & I).Value - _
            (Sheets("Sheets1").Range("B" & I).Value / 10)
        End If
    I = I + 1
    Loop
    End Sub
    This will only put the values in Column C. In case you want to put formulas in Column C then use the formula given by SI and put it in the above code...
    Last edited by Siddharth Rout; Oct 27th, 2008 at 08:32 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

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



Click Here to Expand Forum to Full Width