+ Reply to Thread
Results 1 to 18 of 18

If a condition is met enter a value in a specific cell

Hybrid View

  1. #1
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    If a condition is met enter a value in a specific cell

    Hello,

    I have a long list. In column "C" there are 3 types of values (text):

    1. "Cash" followed by numbers like 1234...
    2. "Bank" followed by numbers as above
    3. Other

    The numbers following Cash or Bank are different.

    What I need is a macro that will search for "Cash" and for "Bank" (without the hyphens) in each cell in column "C" and if it finds it than in Column "S"+1 to insert the value "Cash" or "Bank" depending on what was found.

    For example if in cell "C4" the string "Cash" was found than in cell "S5" the value or text "Cash" to be inserted. If in cell "C50" the string "Bank" is found that this should become the value in the cell "S51".

    Column "S" is blank at the beginning.

    Thank you so much.

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: If a condition is met enter a value in a specific cell

    In S2 put:
    =IF(LEFT(C1,4)="Cash","Cash",IF(LEFT(C1,4)="Bank","Bank",""))
    Assuming 3 (Other) means any other possible value, if it actually means the word "Other" then....

    =IF(LEFT(C1,5)<>"Other",LEFT(C1,4),"")
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Re: If a condition is met enter a value in a specific cell

    Thank you so much. This is wonderful. However I would like this to be a macro so that when it is run the task to be complete. The list is generated by a software and I would not like the user to have to enter formulas on his/her own in column S. Just to run a macro but no entries in cells by the user.

    And yes, "Other" means any other value.

    Once again thank you.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: If a condition is met enter a value in a specific cell

    Perhaps this?

    =if(C4="Cash*","Cash,if(C4="Bank*","Bank","")) (You didnt say what you wanted for Other?)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Re: If a condition is met enter a value in a specific cell

    Quote Originally Posted by FDibbins View Post
    Perhaps this?

    =if(C4="Cash*","Cash,if(C4="Bank*","Bank","")) (You didnt say what you wanted for Other?)
    Thank you so much.

    I do not need anything inserted in column "S" if there is no string "Bank" or "cash" found in a cell of column "C".

    So column C is a list with many rows. I would like the macro to run through each cell in column C and search for string Bank or Cash. If it finds it than in column S, one row below the row in which Cash or Bank was found to insert Cash or Bank.

    Thank you so much for all of your help.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: If a condition is met enter a value in a specific cell

    My VBA is not that good, cant you just take that formula and copy it down?

  7. #7
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Re: If a condition is met enter a value in a specific cell

    Quote Originally Posted by FDibbins View Post
    My VBA is not that good, cant you just take that formula and copy it down?
    Maybe I will try to insert the formula with a help of a macro. The problem is that I will not be working with this workbook but another user which is not very skillful in Excel. The user knows that a macro can be run with Alt+f8 so this way I can be certain that the work will be done successfully.

    This is supposed to be part of a larger macro project which I intend to develop gradually. I am already using code from this forum for it but this piece is missing.

    Thank you.

  8. #8
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: If a condition is met enter a value in a specific cell

    Quote Originally Posted by gokica View Post
    Maybe I will try to insert the formula with a help of a macro.

    As FDibbins say though, you dont need to use a macro and the user doesnt need to insert any formula, simply drag it way way way down further than it will ever need to be, the cells will remain blank until either Cash or Bank is found in the corresponding Column C entry.

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: If a condition is met enter a value in a specific cell

    Perhaps you could change it this this...
    =IF(C4="","",if(C4="Cash*","Cash,if(C4="Bank*","Bank","")))
    and then copy that down way past where you will need it? If C4 is blabk, the cell with that formula (S?) will also show blank

  10. #10
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Re: If a condition is met enter a value in a specific cell

    I am most grateful for the help provided. The form will be generated by a software on the users computer. This will be done more than once. I will not be there to copy the formula in each export to Excel. But once again thank you so much for the most useful input.

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: If a condition is met enter a value in a specific cell

    Maybe:

    Sub gokica()
    Dim i As Long
    For i = Range("C" & Rows.Count).End(3).Row To 2 Step -1
        If Range("C" & i) Like "*Cash*" Then Range("S" & i + 1).Value = "Cash"
        If Range("C" & i) Like "*Bank*" Then Range("S" & i + 1).Value = "Bank"
    Next i
    End Sub

  12. #12
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Re: If a condition is met enter a value in a specific cell

    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe:

    Sub gokica()
    Dim i As Long
    For i = Range("C" & Rows.Count).End(3).Row To 2 Step -1
        If Range("C" & i) Like "*Cash*" Then Range("S" & i + 1).Value = "Cash"
        If Range("C" & i) Like "*Bank*" Then Range("S" & i + 1).Value = "Bank"
    Next i
    End Sub
    This is wonderful. Works beautifully. Thank you so so much.

    I am so grateful for everyone's contribution in this thread.

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: If a condition is met enter a value in a specific cell

    You're welcome. Glad to help out and thanks for the feedback.

  14. #14
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Re: If a condition is met enter a value in a specific cell

    Quote Originally Posted by JOHN H. DAVIS View Post
    You're welcome. Glad to help out and thanks for the feedback.
    I would kindly like to ask just for a little more help. I would also like when Cash or Bank is found than the contents of the adequate row cell in column N to be copied to cell U+1. What would be the macro for copying cell content when the condition is met?

    Thank you so much.

  15. #15
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: If a condition is met enter a value in a specific cell

    Try:

    Sub gokica()
    Dim i As Long
    For i = Range("C" & Rows.Count).End(3).Row To 2 Step -1
        If Range("C" & i) Like "*Cash*" Then
            Range("S" & i + 1).Value = "Cash"
            Range("U" & i + 1).Value = Range("N" & i).Value
        End If
        If Range("C" & i) Like "*Bank*" Then
            Range("S" & i + 1).Value = "Bank"
            Range("U" & i + 1).Value = Range("N" & i).Value
        End If
    Next i
    End Sub

  16. #16
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Re: If a condition is met enter a value in a specific cell

    Quote Originally Posted by JOHN H. DAVIS View Post
    Try:

    Sub gokica()
    Dim i As Long
    For i = Range("C" & Rows.Count).End(3).Row To 2 Step -1
        If Range("C" & i) Like "*Cash*" Then
            Range("S" & i + 1).Value = "Cash"
            Range("U" & i + 1).Value = Range("N" & i).Value
        End If
        If Range("C" & i) Like "*Bank*" Then
            Range("S" & i + 1).Value = "Bank"
            Range("U" & i + 1).Value = Range("N" & i).Value
        End If
    Next i
    End Sub
    Amazing. Thank you so much. I will remember to give a rep once the system allows me to.

    Wishing you a wonderful day.

  17. #17
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Re: If a condition is met enter a value in a specific cell

    Quote Originally Posted by JOHN H. DAVIS View Post
    Try:

    Sub gokica()
    Dim i As Long
    For i = Range("C" & Rows.Count).End(3).Row To 2 Step -1
        If Range("C" & i) Like "*Cash*" Then
            Range("S" & i + 1).Value = "Cash"
            Range("U" & i + 1).Value = Range("N" & i).Value
        End If
        If Range("C" & i) Like "*Bank*" Then
            Range("S" & i + 1).Value = "Bank"
            Range("U" & i + 1).Value = Range("N" & i).Value
        End If
    Next i
    End Sub
    Hello again. I am facing a very strange situation with the code. If I run it separately everything goes well. But if it is part of a larger macro sometimes it works and yet sometimes it does not work and results with "method 'range' of object '_global' failed". Because variable "i" existed I replaced it with "cash". But I do not think that this is the cause. Even if I put it in a separate module and call it from the previous.

    I can not notice difference between the files exported in which it works and in which it does not.

    Is there some substitute or another alternative for this code please.

    Edit: I placed it in a different module but this time I replaced the variable "cash" with "i" and it started working on all exported files.

    I am so sorry for the trouble and taking your time with this post. All is well now. Thank you once again.
    Last edited by gokica; 11-20-2014 at 04:34 AM. Reason: clarified some more

  18. #18
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: If a condition is met enter a value in a specific cell

    Once Again Welcome. Anytime.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Return alt-enter when enter is pressed in a specific cell
    By bigsteve in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2013, 10:21 AM
  2. [SOLVED] Using the Enter key (from a specific cell) to run a macro
    By evertjvr in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-12-2012, 02:10 PM
  3. Enter Date in cell next to another with specific value
    By AdamShack in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-05-2011, 06:51 PM
  4. insert a row with enter on a specific cell
    By Oakie in forum Excel General
    Replies: 5
    Last Post: 07-28-2006, 12:25 PM
  5. [SOLVED] How do I set the Enter key to go to a specific cell?
    By John in forum Excel General
    Replies: 2
    Last Post: 03-18-2005, 08:06 PM

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