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.
 
My bad, that's wierd.

because when i have copied the row from one table to the other, i can't press on the cell after it's been copied. in table 2 where the infromation is placed, when i try to edit one of the cells on table 2. nothing happens. the cursor is just a big pluss symbol
but i can press it to remove it ofc. but it's just the edit function

But i will check other codes and see if that is the problem instead, since it works with you.
 
Last edited:
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If you have other sheet change event scripts in the same sheet you could have problems.

Show me all the code you have in that sheet.
 
Upvote 0
ahh,okey.

here is every code in sheet1, but i use one call to use a module. but that was added after the problem was there.

Code:
Private Sub CommandButton1_Click()If CommandButton1.Caption = "Hide Information" Then
Range("g:l").EntireColumn.Hidden = True
  CommandButton1.Caption = "Show Information"
Else
  Range("g:l").EntireColumn.Hidden = False
  CommandButton1.Caption = "Hide Information"
End If
End Sub

Code:
 Sub Unfilter()'Unfilter all table columns
     ActiveSheet.Range("A2:P2").Select
        If ActiveSheet.FilterMode = True Then
            ActiveSheet.ShowAllData
        End If
End Sub

Code:
Sub insertCheckboxes() 
  Dim myBox As CheckBox
  Dim myCell As Range
 
  Dim cellRange As String
  Dim cboxLabel As String
  Dim linkedColumn As String
 
  cellRange = InputBox(Prompt:="Cell Range", _
    Title:="Cell Range")
 
  linkedColumn = InputBox(Prompt:="Linked Column", _
    Title:="Linked Column")
 
  cboxLabel = InputBox(Prompt:="Checkbox Label", _
    Title:="Checkbox Label")
 
  With ActiveSheet
    For Each myCell In .Range(cellRange).Cells
      With myCell
        Set myBox = .Parent.CheckBoxes.Add(Top:=.Top, _
          Width:=.Width, Left:=.Left, Height:=.Height)
 
        With myBox
          .LinkedCell = linkedColumn & myCell.Row
          .Caption = cboxLabel
          .Name = "checkbox_" & myCell.Address(0, 0)
        End With
 
        .NumberFormat = ";;;"
      End With
 
    Next myCell
  End With
End Sub

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
 
Last edited:
Upvote 0
Well I see nothing doing a quick look that would cause your problem.
I suggest you put my code in a empty sheet with no other code and see what happens.
If it all works OK then you will maybe need to work seeing what other code is causing the issue.
A process of elimination.
 
Upvote 0
If your using Double click instead of checkboxes why do you have this code in your sheet:

Sub insertCheckboxes()
 
Upvote 0
yeah sounds like a solid plan, i just wanted to check here first. since many people here got much more knowledge. if it was a simple word wrong or something.

yeah i forgot to remove that code. woops.
 
Upvote 0
Yes, i made a new sheet. with only your code. I still have the same problem. the code work. copies the row i doubleclick. but when the macro/code i active, I can't edit a cell. the cursor is just a pluss sign.

If i press break, then i can edit the cells. but then the code does not activate.
 
Last edited:
Upvote 0
When i remove your code , i can edit my cells again. so it looks like its the main reason, but i have noe clue why.
because it works with you, correct ?
 
Upvote 0
You did not answer my question

I asked does my script work when you enter it in to a sheet with only my code.

You said if I remove your code all works well. That was not my question.

There is no way for me to test it with all your other code in the sheet unless I was to enter all your other code in my sheet and see what happens.
But that is more then i want to do.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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