Results 1 to 4 of 4

Thread: Insert Value When A Conditin is Met

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Insert Value When A Conditin is Met

    Dear All,

    I've just joined this forum and feel excited to be a part of this. I'm looking for a VB code to have a value being inserted when a condition is being met. For eg., in the attached file, values under Col F i.e Header Comment would have to turn / get inserted as "Same Day Cancel" when the macro is run - header 'd' for a value 'C' in col D.

    All I know is that the above can be accomplished through loops (correct me if I'm wrong, pls) and becomes a bouncer when I attempt to understand such loops as & when I read somewhere! Same Day Cancel.xlsx

    Your help is immensely appreciated. Thanks again in advance. Also, request you to pls share any material on VB to pick things up at a relatively faster rate. I've downloaded a number of soft copies on VBA but the pedagogy isn't too appealing to me unfortunately.

    Thanks a ton for your help again!

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi Ajit,

    Welcome to ExcelFox !!

    You can accomplish by inserting the formula in F4 and copied down,

    =IFERROR(IF(D4="C","Same Day Cancel",""),"")
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0
    Hi Admin!

    Thanks very much for your reply. However, I'm looking for a VB code to do the same in an excel sheet. For eg., I want a loop to be written in VB code such that the loop looks at the whole of a range...say Cell C3 to C5000 and gives the output as "Same Day Cancel" in Col E for any of the cells found in Col C. I've managed to put the below loop in but doesn't work for a given range:


    Code:
     Sub test()
    
    If Range("C3:C5000").Value = "C" Then Range("E3:E5000").Value = "Same Day Cancel"
    
    End Sub
    It only works for a given Cell i.e C3 but not C3:C5000.

    Thanks much for your help. Would you be able to help me put in a loop pls?

    -Ajit

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Try

    Code:
    Sub kTest()
        
        With Range("d3:d5000")
            .Offset(, 2).Value = Evaluate("IFERROR(IF(" & .Address & "=""C"",""Same Day Cancel"",""""),"""")")
        End With
    
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Replies: 2
    Last Post: 07-02-2013, 06:52 PM
  2. Macro To Insert Columns In Excel
    By jac3130 in forum Excel Help
    Replies: 2
    Last Post: 05-17-2013, 07:49 AM
  3. Automatically Insert Row
    By marreco in forum Excel Help
    Replies: 7
    Last Post: 12-21-2012, 06:43 PM
  4. Insert Picture in a Cell UDF
    By Admin in forum Download Center
    Replies: 10
    Last Post: 12-07-2012, 04:49 PM
  5. help with after insert event in Access 10
    By richlyn in forum Access Help
    Replies: 9
    Last Post: 03-03-2012, 10:49 PM

Posting Permissions

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