Linking a cell's comment to a vba form's textbox
- pauly21
- Thread is marked as Resolved.
-
-
-
Unfortunately the code above crashes when trying to run.
I've attached pictures to try and explain better what i'm after.
For example, when selecting cell A4 i want to click the 'run form' box and for the form to display the entire row contents (row 4), whilst still having the ability to use the combobox 1 drop menu (index number on the form) to select other records.
-
That's what the code that I posted does, you need to change the control names and add the other control names
-
If i change the control names (e.g: Me.filesize.Value = ActiveCell.Value) the code just puts the active cell value into all the boxes on the form and not the row contents into the various different boxes.
-
Here's the simplest way, change the code for the UserForm's Initialize event to this
Code
Display MorePrivate Sub UserForm_initialize() With Sheet1 Set rData = Sheet1.Range(.Cells(2, 1), .Cells(.Rows.Count, 43).End(xlUp)) End With Me.ComboBox1.List = rData.Value If Selection.CountLarge > 1 Then Exit Sub If Not Intersect(ActiveCell, rData) Is Nothing Then Me.ComboBox1.ListIndex = ActiveCell.Row End Sub
-
That works if i select the active cell as any cell in the first row (e.g. Row 2)
If i select any cell in row 4 for example then it crashes with this error 'could not set the listindex property,invalid property value'
-
I forgot to allow for the ListIndex starting at zero
Code
Display MorePrivate Sub UserForm_initialize() With Sheet1 Set rData = Sheet1.Range(.Cells(2, 1), .Cells(.Rows.Count, 43).End(xlUp)) End With Me.ComboBox1.List = rData.Value If Selection.CountLarge > 1 Then Exit Sub If Not Intersect(ActiveCell, rData) Is Nothing Then Me.ComboBox1.ListIndex = ActiveCell.Row - 2 End Sub
-
Nope, still crashing with the same error.
-
Apologies Ray, typing error on another line by me caused a crash on the updated code.
Working great now.
Thanks again for the help, you're a gem.
Paul
-
Roy that is
-
Glad you got it working.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!