+ Reply to Thread
Results 1 to 4 of 4

Checkbox and Macro to delete specific data in corresponding row

  1. #1
    Registered User
    Join Date
    02-17-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2003
    Posts
    4

    Exclamation Checkbox and Macro to delete specific data in corresponding row

    I have an inventory spreadsheet. I am trying to make it as user friendly as possible. Currently, the inventory data begins in row 22 (D22;Q22). I would like to add checkboxes for every line of the inventory in column C. The user could then place a check beside all inventory items he/she wanted to delete. Then, I would like to create a macro to delete the corresponding data from that row (if checkmarks in C22 and C41, then delete data from D22;Q22 and D41;Q41) then uncheck all boxes, resort & save the inventory. I already have a macro (assigned to a button) to resort and save the inventory. Could someone help with creating the rest of the needed macro? I am lost.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Checkbox and Macro to delete specific data in corresponding row

    Why dont you attach a sample file with some dummy data?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    02-17-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Checkbox and Macro to delete specific data in corresponding row

    Thank you.

    I have attached a file for your consideration.

    What I'd like to do:
    1) Alter macro to create checkboxes in B22:B5000 linked to C22:C5000 respectively in which the checkboxes would have no caption or text and are possibly centered in the column. See references below.

    2) Create a macro that would search Column C for "TRUE" and delete the information in all respective rows, columns D through Q. Then, my "uncheck" and "reset" macros (already created - "uncheck"- unchecks all boxes, "reset"- re-sorts the information in columns D22:Q22 through D5000:Q5000 and saves the spreadsheet).

    If anyone can help me with any of these macros, I would greatly appreciate it. If you have suggestions for cleaning up my current macros (listed below), that would be helpful as well.


    Reference information:
    1) My current macro for item 1 is as follows:

    Sub ADDCBOXES()
    Dim c As Range
    For Each c In Range("B41:B43")
    c.RowHeight = 15
    ActiveSheet.CheckBoxes.Add(c.Left, c.Top, c.Width, c.Height) _
    .LinkedCell = c(1, 2).Address 'c(1, 2) would offset 1 columns to right
    Next
    End Sub

    2) There are a couple of macros I already have to go along with the code I need.

    This macro will include a message box at the beginning.
    It will most likely look like this:
    Dim nResult As Long
    nResult = MsgBox( _
    Prompt:="Are you sure you want to delete the selected inventory items?", _
    Buttons:=vbYesNo)
    If nResult = vbno Then
    exit sub
    End If
    'rest of macro

    My current re-sort/reset macro looks like this:
    Sub SORT()

    '
    Selection.AutoFilter Field:=1
    Selection.AutoFilter Field:=2
    Selection.AutoFilter Field:=3
    Selection.AutoFilter Field:=4
    Selection.AutoFilter Field:=5
    Selection.AutoFilter Field:=6
    Selection.AutoFilter Field:=7
    Selection.AutoFilter Field:=8
    Selection.AutoFilter Field:=9
    Selection.AutoFilter Field:=10
    Selection.AutoFilter Field:=11
    Selection.AutoFilter Field:=12
    Selection.AutoFilter Field:=13
    Selection.AutoFilter Field:=14
    Range("D22:Q5000").Select
    Selection.SORT Key1:=Range("E22"), Order1:=xlAscending, Key2:=Range("F22" _
    ), Order2:=xlAscending, Key3:=Range("G22"), Order3:=xlAscending, Header _
    :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
    , DataOption1:=xlSortNormal, DataOption2:=xlSortTextAsNumbers, DataOption3 _
    :=xlSortNormal
    Range("B5000").Select
    Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    ActiveWorkbook.Save
    End Sub

    Here is my macro to uncheck all checkboxes
    Sub UNCHECK()
    ActiveSheet.CheckBoxes.Value = False
    End Sub
    Attached Files Attached Files
    Last edited by doubleeinc; 02-22-2012 at 03:52 PM. Reason: update

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Checkbox and Macro to delete specific data in corresponding row

    You have attached 2 worksheets. Which is the right one?

+ 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