Delete Single Cell - VBS

Posted on 2011-10-12
Last Modified: 2012-05-12
Is there a way to delete a SINGLE CELL in an Excel worksheet using VBS?  I want it to delete the cells and move whatever data is to the right of it into that cell.

I've searched around, but it appears you can only delete ROWs.  If that's the case, I'll have to draft the logic that moves the cell contents to the left.

Thanks for whatever help you can be.
Question by:BMIT
    LVL 65

    Accepted Solution

    Hi, in VBS, this should work.


    Const xlToLeft = -4159
    Set objExcel = CreateObject("Excel.Application")
    Set objWB = objExcel.Workbooks.Open("C:\MyBook.xls", False, False)
    Set objSheet = objWB.Sheets(1)
    objSheet.Range("C3").Delete xlToLeft

    Open in new window


    Author Closing Comment

    An eloquent and articulate answer.  I had forgotten that you had to use .Range to delete cells, even if single ones.

    LVL 65

    Expert Comment

    No worries. Thanks for the grade.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    Run .exe file from network share 2 53
    vba find the last empty column 10 71
    Vbscript  output help 10 23
    Post a good COM tutorial 1 20
    I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now