+ Reply to Thread
Results 1 to 16 of 16

VBA code required to replace cell content of a cell based on the value in another cell

  1. #1
    Registered User
    Join Date
    09-29-2020
    Location
    Kuwait
    MS-Off Ver
    13
    Posts
    7

    VBA code required to replace cell content of a cell based on the value in another cell

    I'm new to VBA so require some help
    I've two columns, say A and B with data filled in from rows 1 to 50. The data are in percentage
    I need a code which will overwrite any % in column A, when % in column B is 100% for all the 50 rows

    Thanks in advance
    Last edited by saugatapalit; 10-10-2020 at 03:39 AM. Reason: As advised by Moderator

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: VBA code required

    Please confirm 100% is stored as text or Percentage?


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    09-29-2020
    Location
    Kuwait
    MS-Off Ver
    13
    Posts
    7

    Re: VBA code required

    As percentage

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: VBA code required

    Please Login or Register  to view this content.

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code required

    My understanding...Could be wrong
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  6. #6
    Registered User
    Join Date
    09-29-2020
    Location
    Kuwait
    MS-Off Ver
    13
    Posts
    7

    Re: VBA code required

    Hi,
    I tried out the code, but it didn't replace the % in column A with 0%

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code required

    The reason why you received 2 codes giving 2 different results is due to your explanation not being clear enough...
    I need a code which will overwrite any % in column A, when % in column B is 100%
    Above is open to interpretation...

    Now this tells us exactly what you wanted...
    replace the % in column A with 0%
    Please Login or Register  to view this content.
    Replace above red snippet with
    Please Login or Register  to view this content.

  8. #8
    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
    52,938

    Re: VBA code required

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however the thread title does not really convey what your request is about. Tell us what you are trying to do, not how you think it should be done.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    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

  9. #9
    Registered User
    Join Date
    09-29-2020
    Location
    Kuwait
    MS-Off Ver
    13
    Posts
    7

    Re: VBA code required

    Hi,
    the code is working fine in the tester file. When I'm copying the code in the file in which I'm tracking my project progress, by changing the columns and rows to fit in my sheet, it is not working. My data are in column D and E ranging from rows 12 to 800. When row E12 becomes 100%, D12 will become 0%. there are other data in other columns too....
    I changed your code as follows, But in didn't work:

    #[modified code]
    Dim lr As Long: lr = Cells(Rows.Count, 4).End(xlUp).Row
    Columns(1).Insert
    With Range("D13:D" & lr): .NumberFormat = "0%": .Formula = "=IF(F1=100%,""0%"",E1)": .Value = .Value: End With
    Columns(2).Delete

    #
    Last edited by saugatapalit; 10-10-2020 at 03:40 AM.

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code required to replace cell content of a cell based on the value in another cell

    I suggest you read the Forum rules HERE
    As per Fords post...Rule No 1 has not been fulfilled...Also, Now Rule No 2 has not been fulfilled...

    Your post does not comply with Rule # 2
    2. Programming code must be enclosed in code tags to improve readability. (A, Z)
    Please Login or Register  to view this content.
    So...Edit your post...Highlight the code and press the # button
    We can only assist once you have complied to all...

    Also...In future in order not to waste time on unecessary coding you should always explain in detail what you require and upload a sample file depicting your actual file setup...99% of the time users are not able to amend the supplied code for their purpose...This just proves this once AGAIN...
    Last edited by sintek; 10-10-2020 at 03:29 AM.

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code required to replace cell content of a cell based on the value in another cell

    Edit your post...Highlight the code and press the # button

    And upload your sample file depicting your actual file setup...

  12. #12
    Registered User
    Join Date
    09-29-2020
    Location
    Kuwait
    MS-Off Ver
    13
    Posts
    7

    Re: VBA code required to replace cell content of a cell based on the value in another cell

    The modified code is as follows:
    Please Login or Register  to view this content.
    The intention is when the some cell value in column E becomes 100%, then corresponding column D will be replaced with 0% (for the cells coloured yellow)
    Hope this helps
    Attached Files Attached Files

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code required to replace cell content of a cell based on the value in another cell

    How does values in Col E become 100%...manual manipulation or code...

  14. #14
    Registered User
    Join Date
    09-29-2020
    Location
    Kuwait
    MS-Off Ver
    13
    Posts
    7

    Re: VBA code required to replace cell content of a cell based on the value in another cell

    Manually entered

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code required to replace cell content of a cell based on the value in another cell

    Then every time you manually input 100% the cell in D must become 0%
    Type in 100 in E and see what happens to cell in D

    Make use of this...In Sheet Module
    Please Login or Register  to view this content.
    Also Rule No 1 in Excel...Avoid MERGED CELLS
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    09-29-2020
    Location
    Kuwait
    MS-Off Ver
    13
    Posts
    7

    Re: VBA code required to replace cell content of a cell based on the value in another cell

    Thanks a lot...it works

+ 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] REQUIRED VBA CODE COMING PARTY CODE IN 2col & DISTRICT NAME 3rd col IN LISTBOX
    By sbvaram in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-03-2020, 09:14 AM
  2. [SOLVED] Required vba code for serial no. Short code +series no of combobox value
    By sbvaram in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-30-2020, 06:38 AM
  3. [SOLVED] Required vba code for save party code in group list sheet
    By sbvaram in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-08-2020, 05:04 AM
  4. [SOLVED] Alternate code required for code attached
    By Zahid0111 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-25-2020, 09:57 AM
  5. Code Help required. Please
    By khalid79m in forum Excel General
    Replies: 4
    Last Post: 01-04-2007, 03:43 AM
  6. Code help required
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2006, 12:25 AM

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