Copy text to other sheet using button and checkbox

CV899000

Board Regular
Joined
Feb 11, 2016
Messages
98
Hi

I have a excel sheet with 50 rows and 17 columns.

I have 1 button in the top of the sheet and I have one checkbox in column A of each row.

I need a VBA code that can do the following:

When a checkbox is checked and the button in the top of the sheet is pressed, then excel should copy the row that the checkbox corresponds to but only C:S in that row, not A or B, into a separate sheet into C:S. It should paste the data on the next free row, so if I already have transferred data it will not overwrite.

Furthermore after copying from the original sheet, it should delete the information in the row and move all other data up so the data always is on the top rows.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I have the following until now:

Code:
Option Explicit
Sub Buttons()
    Dim ws As Worksheet
    Dim lngRow As Long
    Dim rngButton As Range
    Dim shpButton As Shape
    Set ws = ThisWorkbook.Worksheets("Current orders")
    'ws.Cells.Delete
    'create a sequence of buttons
    For lngRow = 3 To 52
        'get a range
        Set rngButton = ws.Cells(lngRow, 1)
        'use range properties to define button boundaries
        Set shpButton = ws.Shapes.AddFormControl(xlButtonControl, _
            rngButton.Left, _
            rngButton.Top, _
            rngButton.Width, _
            rngButton.Height)
        'add button properties - action, caption and alt text
        With shpButton
            .OnAction = "DoButtonAction"
            .OLEFormat.Object.Text = "Complete " & lngRow
            ' store the cell address here
            .AlternativeText = rngButton.Address
        End With
    Next lngRow
End Sub
Sub DoButtonAction()
    Dim shp As Shape
    Dim strControlName As String
    Dim strAddress As String
    Dim rngButton As Range
    'get button name
    strControlName = Application.Caller
    'get alternative text which has cell address
    strAddress = ActiveSheet.Shapes(strControlName).AlternativeText
    'get range corresponding to button and do stuff with cells in that row
    Set rngButton = ActiveSheet.Range(strAddress)
    'copy cell value for use later
    rngButton.Offset(0, 1).Copy

End Sub

This creates buttons instead of checkboxes, that's fine. But I can only copy 1 cell now. How do I copy a range using this?
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,443
Members
448,898
Latest member
drewmorgan128

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