Hi,
I have worksheet with checkboxes on each row that when enabled, the row data will be copied on a master file. This works well, however, vba runs slowly even I turn off excel applications.
I duplicate the codes for each checkboxes changing only the range of the rows to copy. I want to have one code instead of duplicating the codes for each checkbox. If you can help me shorten the code, might help to speed up my vba.
This is the code I use for each checkboxes:
I have worksheet with checkboxes on each row that when enabled, the row data will be copied on a master file. This works well, however, vba runs slowly even I turn off excel applications.
I duplicate the codes for each checkboxes changing only the range of the rows to copy. I want to have one code instead of duplicating the codes for each checkbox. If you can help me shorten the code, might help to speed up my vba.
This is the code I use for each checkboxes:
Code:
Private Sub CheckBox1_Click()Dim wsTarget As Workbook
Dim wsSource As Workbook
Dim rngSource As Range
Dim rngTarget As Range
Dim wbname As String
With Excel.Application
.ScreenUpdating = False
.Calculation = Excel.xlCalculationManual
End With
wbname = "C:\Users\IT SUPPORT\Documents\Blotter\Master.xlsm"
Set wsSource = ActiveWorkbook
Set wsTarget = Workbooks.Open(wbname)
Worksheets("Master").Select
Worksheets("Master").Range("B6").Select
Set rngSource = wsSource.Sheets("Blotter").Range("B7:N7")
Set rngTarget = Worksheets("Master").Range("B" & (Worksheets("Master").Range("B65536").End(xlUp).Row + 1))
If CheckBox1.Value = True Then
rngSource.Copy
rngTarget.PasteSpecial xlPasteValues
wsSource.Worksheets("Blotter").Activate
End If
wsTarget.Close True
With Excel.Application
.ScreenUpdating = True
.Calculation = Excel.xlAutomatic
.CutCopyMode = False
End With
End Sub