+ Reply to Thread
Results 1 to 2 of 2

Checkboxes on form

  1. #1
    Registered User
    Join Date
    08-10-2010
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2003
    Posts
    3

    Question Checkboxes on form

    Hi everyone,

    I need to create a VBA form that deletes defined cells in Excel with a code like this one : Range("A1, B1, C1, D1, E1").ClearContents. I want to add checkboxes to the form, each permitting to delete a different row (1st checkbock would delete the first row, 2nd checkbox would delete the second row and so on). The change would only occur when the OK button is pressed (several rows could then be deleted at the same time if their checkboxes are checked). Since I have very limited backgroud in VBA, I don't know how to code this so the change can only happen once the OK button is clicked. Do you have suggestions? Any help is much appreciated.

    Narfcois

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Checkboxes on VBA form for Excel

    Hi,

    Not quite sure why you mention cells on row 1 and then talk about deleting rows 1,2, etc. but assuming I've interpreted correctly, put your code in the Click event of the OK Command Button. Untested but something like

    Please Login or Register  to view this content.
    etc. If there are many checkboxes you might be better to write a loop to process them rather than repeat many lines of similar syntax to the above.

    I generally process these things in descending order. It doesn't matter in this example since you are only clearing contents, but on other occasions you may be deleting rows and then the order is important and it's a good habit to get into. If you want to delete say rows 2 & 4 and the macro processed row 2 first then what was row 4 becomes row 3 before the next instruction to delete a row is activated, and the second instruction will then still delete row 4 which contains what were row 5 values.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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