+ Reply to Thread
Results 1 to 11 of 11

Macro to check and delete content of cell

  1. #1
    Forum Contributor
    Join Date
    07-24-2013
    Location
    HongKong
    MS-Off Ver
    Excel 2010
    Posts
    237

    Macro to check and delete content of cell

    Dear all,

    I want to write a macro which will run in relative cell references

    1. The macro starts at cell A1, say, activated by ctrl"k"
    2. After the macro starts, it checks the content of cell C1
    3. If C1 is a space, delete the cell content, then goto C2.
    4. If C1 is not a space, skip to C2
    5. Repeat step 3 & 4 up to C100
    6. After all the 100 cells are checked and deleted if necessary, the macro stops at cell K1.

    Thank you for your assistance.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to check and delete content of cell

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-24-2013
    Location
    HongKong
    MS-Off Ver
    Excel 2010
    Posts
    237

    Re: Macro to check and delete content of cell

    Quote Originally Posted by stnkynts View Post
    Please Login or Register  to view this content.


    Thank you stnkynts.

    Your macro is written in absolute cell reference mode, how about in relative cell reference mode please?

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

    Re: Macro to check and delete content of cell

    Try
    Please Login or Register  to view this content.

  5. #5
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Macro to check and delete content of cell

    If you want it to run relative and I assume by this you mean run for rows 1 to 100 but 2 columns to the right (based on your description above of starting in A1 and running in column C) then try this. It uses Stnkynts macro but modifies to run in the column two columns to the right and starting at the same rown number as the present activecell

    Please Login or Register  to view this content.
    Happy with my advice? Click on the * reputation button below

  6. #6
    Forum Contributor
    Join Date
    07-24-2013
    Location
    HongKong
    MS-Off Ver
    Excel 2010
    Posts
    237

    Re: Macro to check and delete content of cell

    [QUOTE=Crooza;4012598]If you want it to run relative and I assume by this you mean run for rows 1 to 100 but 2 columns to the right (based on your description above of starting in A1 and running in column C) then try this. It uses Stnkynts macro but modifies to run in the column two columns to the right and starting at the same rown number as the present activecell

    [CODE]Sub kent()
    Dim c As Range


    Dear Crooza,

    Thank you for your suggestion.

    1. Actually I need to clear the cell content if the cell content a space, but not only trim the space. As the space is resulted by a formula set in the cell, and this formula should be cleared as well.

    2. Your Macro always stops at K1, I want it stops 10 columns to the right, i.e. stop at K1 when start at A1, stop at L1 when start at B1.

    Any new idea please help again.

    Kent

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

    Re: Macro to check and delete content of cell

    Please Login or Register  to view this content.

  8. #8
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Macro to check and delete content of cell

    This should address point 2 above. In regard to point 1 the first code should have addressed a space regardless of whether it was the result of a formula or simply text. Maybe post your worksheet up so we can see what isn't working

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    07-24-2013
    Location
    HongKong
    MS-Off Ver
    Excel 2010
    Posts
    237

    Re: Macro to check and delete content of cell

    Dear Crooza and jindon,

    I got it by using your suggestion "Range(ActiveCell.Offset(0, 10), ActiveCell.Offset(0, 10)).Select" to solve the stop position.
    I have also used "If cell.Value = " " Then cell.ClearContents" to clear the cell content.

    Thanks a lot.
    Kent

  10. #10
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Macro to check and delete content of cell

    Great. Glad it worked. You should mark the thread as solved now

  11. #11
    Forum Contributor
    Join Date
    07-24-2013
    Location
    HongKong
    MS-Off Ver
    Excel 2010
    Posts
    237

    Re: Macro to check and delete content of cell

    Quote Originally Posted by Crooza View Post
    Great. Glad it worked. You should mark the thread as solved now

    Marked as told.

+ 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] Adjust a macro to check for content of a cell and then run a macro on target sheet
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2013, 04:37 AM
  2. [SOLVED] Find rows to delete with a macro based on cell content
    By mkraffert in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-28-2013, 06:27 PM
  3. Macro to delete cell content based on cell value
    By stevetothink in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-29-2013, 10:57 AM
  4. [SOLVED] Macro to delete rows if any cell contains specific content
    By adayoan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-31-2012, 07:11 PM
  5. [SOLVED] How to check a cell for content before running macro.
    By Incoherent in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2005, 12:05 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