+ Reply to Thread
Results 1 to 15 of 15

VBA Modify cell values in a range

  1. #1
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    VBA Modify cell values in a range

    This is just a sample macro i found somewhere and just edited (I know this is wrong).

    Please Login or Register  to view this content.
    What I want is:
    1. If I put CANCELLED on column A, the values on column N,O,P,Q,R becomes "," + their current value.
    2. Skip or ignore blank cells in N,O,P,Q,R.

    I will be using from A5 to A1500, so with NOPQR.

    Thank You so much.
    Last edited by domz3669; 04-11-2018 at 08:34 PM.

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Kindly modify this Macro please!

    Please check forum rule 3. Use code tags around code.

    You will likely want to change the thread title as well ... to something more descriptive ... before a Mod/Admin stops others from posting.
    Dave

  3. #3
    Registered User
    Join Date
    06-17-2012
    Location
    Australia
    MS-Off Ver
    MS Office 365
    Posts
    40

    Re: VBA Modify cell values in a range

    I'm sure there are better/faster ways but this works with little modification.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this ‼


    A formula way :

    PHP Code: 
    Sub Demo1()
           Const 
    "TRANSPOSE(IF(#=""CANCELLED"",ROW(#)))"
        
    For Each V In Filter(Evaluate(Replace(F"#"ActiveSheet.UsedRange.Columns(1).Address)), FalseFalse)
            
    With Cells(V14).Resize(, 5)
                .
    Value Evaluate(Replace("IF(#>"""","",""&#,"""")""#", .Address))
            
    End With
        Next
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-11-2018 at 09:50 PM.

  5. #5
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: VBA Modify cell values in a range

    -bradl822
    Thanks for the code. I tested it, works fine if there is only one row used. When i move to A2 and put cancelled, it adds another comma to any cell with cancelled. In short, every time i use the code, all rows with cancelled adds additional comma to their values. Hope someone can improve your code.

    -Marc L
    For some reason, when I use the code, all the base values from N,O,P,Q,R becomes empty.

    Here I will upload the file. I will use the code on the first sheet.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    On my side it rocks at a glance, so something weird with your workbook …
    Anyway, try this
    (and you can try the easy Find method for a faster execution maybe, as you can see within VBA inner help) :

    PHP Code: 
    Sub Demo1a()
            Const 
    "TRANSPOSE(IF(#=""CANCELLED"",ROW(#)))"
            
    Application.EnableEvents False
        
    For Each V In Filter(Evaluate(Replace(F"#"Range("A5", [A4].End(xlDown)).Address)), FalseFalse)
            
    With Cells(V14).Resize(, 5)
                .
    Value Evaluate(Replace("IF(#="""","""","",""&#)""#", .Address))
            
    End With
        Next
            Application
    .EnableEvents True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA Modify cell values in a range

    VBA option that does not add multiple commas:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  8. #8
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: VBA Modify cell values in a range

    - Marc L
    Thank you for the code but still it adds another comma to the previous cancelled cells...

    - Arkadi
    Perfect pal, just what I needed. If you could edit the code to something like, if its not cancelled, then remove the existing commas, I thank you so much. But the code alone is enough for me.. Again Thank You!

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA Modify cell values in a range

    I am not at a computer right now but will post an update in the morning to remove a leading comma if the value of column A is not "CANCELLED"

  10. #10
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: VBA Modify cell values in a range

    Thank you, I will wait.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA Modify cell values in a range

    This should do
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: VBA Modify cell values in a range

    Hi Jin,
    The formula removes commas on non cancelled room, however it add commas to the blank cells on a current cancelled room.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA Modify cell values in a range

    Then change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    04-02-2018
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    24

    Re: VBA Modify cell values in a range

    Works perfectly now!!! Thank you so much Jin and all those who help!!!

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Quote Originally Posted by domz3669 View Post
    Thank you for the code but still it adds another comma to the previous cancelled cells...
    Yes in case if you run it twice but as a demonstration you can tweak the formula.

    Anyway, thanks for the rep' !

+ 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. Kindly advise what's wrong with the macro
    By hx632 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-22-2015, 12:05 PM
  2. Count for specific criteria
    By Stealthbynature in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-07-2015, 06:49 PM
  3. kindly help for this
    By simakarn1111 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2014, 05:57 AM
  4. [SOLVED] Kindly help in getting the numbers from right side as it is
    By Kumar S in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-28-2014, 08:11 AM
  5. Kindly assist with pivot chart macro
    By ejima in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2012, 03:02 PM
  6. kindly help to solve as below
    By sid_12 in forum Excel General
    Replies: 2
    Last Post: 07-08-2010, 03:35 PM
  7. urgent --kindly help
    By indiewolf in forum Excel General
    Replies: 3
    Last Post: 07-13-2006, 04:30 PM

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