+ Reply to Thread
Results 1 to 16 of 16

VBA to delete cells in a row

  1. #1
    Registered User
    Join Date
    06-21-2010
    Location
    Texas, San Antonio
    MS-Off Ver
    Excel 2007
    Posts
    57

    VBA to delete cells in a row

    Hello all,

    I wrote this script but I am having problems with the code working correctly, what I am trying to due is if you put a x is the cell range of R40 to V40, it will delete the rest of the cells so that there is only one x in the row.
    Any help will be greatly appreciated.

    Thanks,


    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: VBA to delete cells in a row

    try this,

    Please Login or Register  to view this content.
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Registered User
    Join Date
    06-21-2010
    Location
    Texas, San Antonio
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: VBA to delete cells in a row

    Thanks for the help

    I have tried the code, but puts my excel sheet into on infinite loop is there a way to have run it once

    Thanks

  4. #4
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: VBA to delete cells in a row

    can you share your code ?

  5. #5
    Registered User
    Join Date
    06-21-2010
    Location
    Texas, San Antonio
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: VBA to delete cells in a row

    Thanks

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: VBA to delete cells in a row

    can you post the values as this code runs without any issue on my side

  7. #7
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: VBA to delete cells in a row

    opps,

    you have posted this code in the worksheet.change event.

    Why do you want to do this as it will keep running whenever you change any cells contents.

  8. #8
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: VBA to delete cells in a row

    why don't you use it in the selection change event.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-21-2010
    Location
    Texas, San Antonio
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: VBA to delete cells in a row

    Yeah, no problem

    I put the code in the sheet, and I typed in a "x" in the range and the excel sheet displays my "x" but then it locks up and does let me type anything else.

    Thanks

  10. #10
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: VBA to delete cells in a row

    did you remove this code :


    Please Login or Register  to view this content.
    this should be

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-21-2010
    Location
    Texas, San Antonio
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: VBA to delete cells in a row

    I have updated the code to

    Please Login or Register  to view this content.
    Did I paste the code wrong? sorry I am still learning vba

  12. #12
    Registered User
    Join Date
    06-21-2010
    Location
    Texas, San Antonio
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: VBA to delete cells in a row

    I tried this, but the code does not run, am I on the right track??

    Please Login or Register  to view this content.
    Thanks
    Last edited by Coldsteel; 01-16-2014 at 06:40 AM.

  13. #13
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: VBA to delete cells in a row

    Actually the initial code was assigned to a button , so when you click that it will clear all cells that do not have the value "X" in the range.

    Out on break, will look into this when i get back.

  14. #14
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: VBA to delete cells in a row

    Hi Coldsteel,

    Let us know how this goes:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  15. #15
    Registered User
    Join Date
    06-21-2010
    Location
    Texas, San Antonio
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: VBA to delete cells in a row

    I have been testing the code all day, this is work great!!!

    thank you all for the help

  16. #16
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: VBA to delete cells in a row

    Thanks for letting us know and you're welcome

+ 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] Search for red filles cells or certain text strings cells in Column A and delete row.
    By The Skipper in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2013, 12:57 PM
  2. Replies: 2
    Last Post: 07-25-2013, 01:01 PM
  3. [SOLVED] Macro to delete blank cells and unwanted cells in a particular column
    By Nikkishr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-09-2012, 06:22 PM
  4. [SOLVED] Find cells which contain specific word, delete cells and shift left.
    By BPSJACK in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2012, 07:00 AM
  5. Replies: 6
    Last Post: 01-15-2012, 08:57 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