'two command buttons on a worksheet to show the same userform
My Problem:
I have one userform. To open this userform, I use two command buttons. With one command button, I add the data and with second command button (actually not a button but by double clicking on the row from a range), I actually update the existing data of the selected row of the active cell.
My requirement:
With the second function, I would like to hide certain checkboxes and textboxes as well as show a new textbox which is not a part of the first command button.
I hope I was clear to state my problem. Thank you and look forward for your solutions.
First commad button code
Sub Button3_Click() Data_Entry.Show End Sub
Second code from the worksheet function
'''''
> ''''' Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range,
> Cancel As Boolean)
>
> If Not Application.Intersect(Target, Range("A2:N250")) Is Nothing Then
> Cancel = True
> Data_Entry.Show Modal
> With Data_Entry
> Dim strCellComment As String
> Dim CurrentRow As Long
> Dim ws As Worksheet
> Set ws = Sheets("Sheet1")
> .ComboBox5.Text = ws.Cells(CurrentRow, 3)
> .ComboBox6.Text = ws.Cells(CurrentRow, 4)
> .ComboBox7.Text = ws.Cells(CurrentRow, 5)
> .ComboBox4 = ws.Cells(CurrentRow, 27)
> '.TextBox3.Text = ws.Cells(CurrentRow, 3).Comment ': ws.Cells(CurrentRow, 3).Comment.Text Text:=Chr(100) End With
>
> Else Cancel = False End If
Lets say I would like to hide certain textbox when i use the double click function
Solution 1:[1]
The quick answer to how to hide a textbox is to simply add in a line like this:
TextBox1.Visible = False
However, I think a better method for you would be to just create a separate userform for this task. You can copy your existing userform (code and all) by right-clicking on it and clicking export, changing the name so you don't get a conflict, and then right-clicking and importing it back. Then make your changes and you're done!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ben Mega |