"A peg lower than Novice" -- I've setup over 200 command buttons with each lying on top of a cell in a column. The buttons are named using that column (the column being operated on) such as cmdToValues_KB. I created a small sub to:
- copy the column range
- paste result values to replace the formulas in each cell of the column range
- change the button backcolor to indicate the process was completed for that column range
- focus the cell under the button (not included in the copy/paste range)
- and activate another sheet (done in sub where date change prompting to be used or automated)
...all of which works as expected.
What I'd like to discover is how to use VBA to write the code below on the fly, but using the column designation letters in the corresponding places in the sub. For example (partial approximation)...
- Build a line concatenating:
- Private Sub cmdToValues_
- AC (example column letters in a variable?)
- with _Click()
- (insert editor linefeed)
- Build several lines of code eactly as shown below which would otherwise be 100% redundant (with editor linefeeds)
- Build lines of code concatenating code fragments such as (single line example):
- Range("
- AC (column letters)
- 10:
- AC (column letters)
- 247").Copy
- (insert editor linefeed)
- etc.
-- This code would be created upon clicking the button for that column, then the code would hopefully also be able to execute the created sub based on the initial click...or in some simple fashion. My also undiscovered idea was to determine the column from a substring of the button name and use it in a variable to plug into the code-writing scenario. Example static code sub to be used at each column through B through KB:
[VBA]Private Sub cmdToValues_B_Click()
On Error Resume Next
ActiveSheet.Unprotect
If Err.Number <> 0 Then
MsgBox "Password Declined —> ( Is your CAPS Lock On? )", vbInformation
Exit Sub
End If
On Error GoTo 0
Range("B10:B247").Copy
Range("B10:B247").PasteSpecial xlPasteValues
Application.CutCopyMode = False
ActiveSheet.Protect Password:="thelma"
Range("B9").Select
cmdToValues_B.BackColor = &H80000002
date_chg_prompt
End Sub
[/VBA]