+ Reply to Thread
Results 1 to 4 of 4

Deleting Macro

  1. #1
    Registered User
    Join Date
    04-04-2005
    Location
    Bahama, NC
    Posts
    59

    Deleting Macro

    Ok here is one, I am trying to create a macro ( one button) that will when pushed delete certain cells in a row.
    What I am wanting to do is, if I select row 3, it will delete cells a,c,d,e,g becuase I have formulas in b,f,h,i. I don't want them deleted I just need the other cells information deleted and the cells with formulas will clear automatically. But it has to work by selection, if I click 3 it will only work in 3, or if I click 7 if will only work in 7.
    Any Ideas? I gave up after a day, didn't have the time to worry about it anymore, so I purpose it to you all.
    Thanks for the help,
    Bob

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Robert,

    This macro will check the row based on the active cell and then delete the appropriate cells. Paste the code into your command button. This example uses CommandButton1.


    Private Sub CommandButton1_Click()

    Dim R As Long

    R = Excel.ActiveCell.Row
    With Excel.ActiveSheet
    .Cells(R, "A").Value = ""
    .Cells(R, "C").Value = ""
    .Cells(R, "D").Value = ""
    .Cells(R, "E").Value = ""
    .Cells(R, "G").Value = ""
    End With

    End Sub


    If you want to restrict this to a specific worksheet change With Excel.ActiveCell to With Excel.Worksheets("<worksheet name>").

    Hope you find this useful,
    Leith Ross
    Last edited by Leith Ross; 04-13-2005 at 03:52 AM.

  3. #3
    Registered User
    Join Date
    04-04-2005
    Location
    Bahama, NC
    Posts
    59
    Thanks That works really well, I have to change some of my sorts, but that is ok. Unless there is a way to delete instead of assigning "" as a value. Is it possible to make so I can remove multiple rows of information instead of one at a time?
    Thanks again for the help.
    Bob

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Bob,

    Yes you can clear out multiple rows. I will have to rewrite the macro to do that. With regard to deleting the cells, I am guessing that a Empty or Blank cell causes your sorting to stop a that cell. The cells can be deleted, that is shifted up, to prevent a sorting problem. I'll work on a rewrite today for you.

    Thanks,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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