+ Reply to Thread
Results 1 to 11 of 11

Macro for clearing contents and adding serial number after validating

  1. #1
    Registered User
    Join Date
    03-21-2016
    Location
    SG
    MS-Off Ver
    2010
    Posts
    23

    Macro for clearing contents and adding serial number after validating

    Hi all,

    I am beginner and I need help in writing macros.

    I have an excel with 4 columns(column A: DCODE(A1), column B: NAME(B1), column C: USERID(C1), column D : ROLE(D1)). I have values for all the cells in column A and some cells have values in column B.
    I am trying to do the following.

    1. Change the value of A1 from DCODE to SNO
    2. Clear the values in column A (except the cell A1)
    3. Check the value in column B and if it has a name then the serial number should be given in the column A. Serial number should be there only if a name is there in column B.


    Please help.. thanks

  2. #2
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: Macro for clearing contents and adding serial number after validating

    Try this:

    HTML Code: 

  3. #3
    Registered User
    Join Date
    03-21-2016
    Location
    SG
    MS-Off Ver
    2010
    Posts
    23

    Re: Macro for clearing contents and adding serial number after validating

    Thanks for supporting me.
    After executing with the above code, noticed number generates from 1 to 4 in column A(for first 4 rows even though data is not there in column B).
    From row5 number 2 is always displayed if it's null value in column B.

  4. #4
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: Macro for clearing contents and adding serial number after validating

    Please upload a file and simulate an answer.

  5. #5
    Registered User
    Join Date
    03-21-2016
    Location
    SG
    MS-Off Ver
    2010
    Posts
    23

    Re: Macro for clearing contents and adding serial number after validating

    Please find the attachment. It has the current output and the required output. thanks
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: Macro for clearing contents and adding serial number after validating

    HTML Code: 

  7. #7
    Registered User
    Join Date
    03-21-2016
    Location
    SG
    MS-Off Ver
    2010
    Posts
    23

    Re: Macro for clearing contents and adding serial number after validating

    First row (value of cell A2) is not changed. Remaining rows works correctly.

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Macro for clearing contents and adding serial number after validating

    Try it like this....
    Please Login or Register  to view this content.
    Or try this simple version

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  9. #9
    Registered User
    Join Date
    03-21-2016
    Location
    SG
    MS-Off Ver
    2010
    Posts
    23

    Re: Macro for clearing contents and adding serial number after validating

    Thanks a lot ikboy and sktneer. It works perfect now..
    It solved my purpose. Thanks again

  10. #10
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Macro for clearing contents and adding serial number after validating

    You're welcome. Glad we could help.

    If that takes care of your original question, please mark your thread as Solved by selecting Thread Tools (just above your first post) --> Mark thread as solved.

    You may also say thanks to those who have put their time and efforts to help you in this forum by clicking the Add Reputation link under one of their posts, another way to say thanks.

  11. #11
    Registered User
    Join Date
    03-21-2016
    Location
    SG
    MS-Off Ver
    2010
    Posts
    23

    Re: Macro for clearing contents and adding serial number after validating

    Sure will do it definitely.

    One last thing whether is it possible to insert an empty row after each persons record. Thanks

+ 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. Adding a new number row but clearing contents of new role
    By Armored Wing in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-11-2014, 11:18 PM
  2. Replies: 0
    Last Post: 06-29-2014, 03:05 AM
  3. [SOLVED] Macro is not copying to other sheet, just clearing contents of select case
    By Rokn in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 11-21-2013, 09:06 AM
  4. program error and adding monitor serial number
    By mhelpdesk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2011, 10:36 AM
  5. Help with clearing contents macro
    By Chadwick24 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-24-2009, 02:25 PM
  6. Validating mixed data fields (serial numbers)
    By gavsev in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-17-2009, 08:45 AM
  7. Macro Help for Deleting Blank Rows & Clearing Cell Contents
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2006, 01: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