ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Control Toolbox Checkbox Macro - Help Please! (https://www.excelbanter.com/excel-programming/379935-control-toolbox-checkbox-macro-help-please.html)

[email protected]

Control Toolbox Checkbox Macro - Help Please!
 
I am trying to write a code that when the Copy Prior Line checkbox is
clicked, it copies the line two rows above and paste special (values
only) into the same line as the checkbox (i.e. copies line 27 into line
29). But I want to make one general macro that I can apply to every
Copy Prior Line checkbox, but I seem to have to use a line number...
Please help!

Also, can I apply this macro to every checkbox? Thank you and I really
appreciate the help...


Private Sub CheckBox2_Click()


Dim k As Integer


If CheckBox2.Value = True Then


Application.ScreenUpdating = False


With Range("B27:B300")


For k = 29 To 300


If Range("B" & k) = "True" Then
Range("B" & k - 2, "BI" & k - 2).Select
Range("B" & k - 2, "BI" & k - 2).Copy
Range("B" & k, "BI" & k).Select
Selection.PasteSpecial xlPasteValues
Application.CutCopyMode = False
Range("B" & k).Select


Else: GoTo 10
End If


Next k


10


End With


End If


End Sub



All times are GMT +1. The time now is 01:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com