Consulting

Results 1 to 3 of 3

Thread: VBA to delete cells based on cell selected and move cells up

  1. #1

    VBA to delete cells based on cell selected and move cells up

    Hi guys

    i have a bunch of data:

    Register Read Date Usage
    R0001 8675 12-Nov-13 21.82142857
    R0001 9286 10-Dec-13 21.90625
    R0001 10688 12-Feb-14 25.04761905
    R0001 11214 05-Mar-14 22.89795918
    R0001 12336 23-Apr-14 24.33333333
    R0001 12993 20-May-14 19.95714286
    R0001 14390 29-Jul-14 19.35483871
    R0001 14990 29-Aug-14 20.32142857

    I want to create a button where a person can select a cell and when they push the button it will remove all data in the 4 cells in that range. It then needs to move all other data up to replace what will be an empty row. It then needs to refresh the code in the usage.

    Refreshing the code bit i can do but i can't seem to get the rest of it to work.

    I dont want to delete the whole row as i have other data in those rows, i just want those 4 cells removed.

    eg if i select d3 from above (21.90625) i want A,B and C3 all removed and then everything below moved up to replace.

    Any help would make me a very happy bunny.

    Cheers guys/girls.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,910
    Location
    Test this on a backup. I don't think that it will do what you expect.

    You can attach a file. Click the Go Advanced button in lower right of a message, and then click the paperclip icon to Browse and Upload your simple example file.

    Sub Main()  
      Range("A" & Selection(1).Row, "D" & Selection(1).Row).Delete Shift:=xlUp
    End Sub

  3. #3
    That's pretty much what i was after! I realise now where i was going wrong

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •