Commandbutton to copy based on CheckBox True/False

TDNova

New Member
Joined
Apr 16, 2018
Messages
45
Hello, im trying to figure out how to make this work.

I got a table with informaton. with a checkbox on the side of the table.
simply explained:
When the checkbox on the row is true, copy table row "b3:p3" to a new table.
but i want it to be activated by a commandbutton, so i can choose 5 checkboxes before it starts to copy.

Is there a way for it to work without linking each and every checkbox to the cells?

I do not have enough knowlegde in excel to know which approach is best suited here.
 
If you have formulas in these cells and then copy the cells to another location it can throw off your formulas.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
If you have formulas in these cells and then copy the cells to another location it can throw off your formulas.
Yes !! that could be the problem. i totally forgot about that.
they are getting data from another sheet. because i got typeid and type .For example type id is 2 then type is "stusser"

Is it possible to copy A to p but not I , and rather but the formula in the orderoversikt table where the I information should be. so it pulls information from the same spot.

Give me some time and i will clear this up, and then we can fix it. i found a way to fix this mess
 
Last edited:
Upvote 0
Why A to P but not I

We can copy just the values which would mean you would get the values currently in the cell but the cell would no longer update if something caused the formulas to change.
 
Upvote 0
I think we can deacrease the information that is needed to copy. right now table one "Lageroversikt" is from a to p

but on table two "orderoversikt" is only r to w now. i do not need all the columns.

i only need B,C,D,E,F and M on table "orderoversikt.

those got no formulas and they are the only information needed to get copied.

is it possible to decided which columns to be copied ? with table title or is it better to choose columns.

both tables got the same titles
 
Last edited:
Upvote 0
Try this:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 5/29/18 11:40 AM EDT
Cancel = True
Dim cc As Long
Dim Lastrow As Long
Dim r As Long
Dim c As Long
cc = ActiveSheet.ListObjects("Lageroversikt").ListColumns(1).Range.Column
If Target.Column = cc Then
Lastrow = ActiveSheet.ListObjects("Orderoversikt").Range.Rows.Count + 1
ActiveSheet.ListObjects("Orderoversikt").ListRows.Add AlwaysInsert:=True
r = Target.Row
c = Target.Column + 1
Cells(r, c).Resize(, 5).Copy ActiveSheet.ListObjects("Orderoversikt").Range.Cells(Lastrow, 1)
Cells(r, "M").Copy ActiveSheet.ListObjects("Orderoversikt").Range.Cells(Lastrow, 6)
End If
End Sub
 
Upvote 0
Try this new script.
It also has the delete function.
Double click on any cell in Column(1) of table Named Orderoversikt
And that row will be deleted from the table

I also made the other requests you had in your last posting.


Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 5/30/18 12:55 AM EDT
Cancel = True
Dim cc As Long
Dim ccc As Long
Dim Lastrow As Long
Dim r As Long
Dim c As Long
cc = ActiveSheet.ListObjects("Lageroversikt").ListColumns(1).Range.Column
ccc = ActiveSheet.ListObjects("Orderoversikt").ListColumns(1).Range.Column
If Target.Column = cc Then
    Lastrow = ActiveSheet.ListObjects("Orderoversikt").Range.Rows.Count + 1
ActiveSheet.ListObjects("Orderoversikt").ListRows.Add AlwaysInsert:=True
r = Target.Row
c = Target.Column + 1
Cells(r, c).Resize(, 5).Copy ActiveSheet.ListObjects("Orderoversikt").Range.Cells(Lastrow, 1)
Cells(r, "M").Copy ActiveSheet.ListObjects("Orderoversikt").Range.Cells(Lastrow, 6)
End If
'Delete Part
If Target.Column = ccc Then
 Dim rng As Range
    
    On Error Resume Next
    With Selection.Cells(1)
        Set rng = Intersect(.EntireRow, ActiveCell.ListObject.DataBodyRange)
        On Error GoTo 0
        If rng Is Nothing Then
            MsgBox "Please select a valid table cell.", vbCritical
        Else
            rng.Delete xlShiftUp
        End If
    End With
End If
End Sub
 
Upvote 0
It worked! thanks for all the time you have invested in helping me. much appreciated.
This will make it so much cleaner than the checkboxes, so thanks for the tip!
 
Upvote 0
It worked! thanks for all the time you have invested in helping me. much appreciated.
This will make it so much cleaner than the checkboxes, so thanks for the tip!

Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Upvote 0
I got a question,
Is it possible to change the code so i could be able to edit the last column on the copied row ?
because now we copy 6 cells of information, but since we got the doubleclick to remove the copied row. i lost the option to press on a cell to edit.

is there a way to fix this ? because i would like to have the option to edit the last column W "the last column"
 
Upvote 0
Not sure what your saying.
My script should have no effect on modify other cells on the sheet.

You said:
i lost the option to press on a cell to edit.
your saying you cannot click on any cell on the sheet to edit it?
What happens when you try to edit.
I just check on my script and i have no issues.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top