For a VBA code in Excel (not a userform) I have 4 textboxes named TextBox1
to TextBox4
.
I want to obtain the values from these textboxes using a for loop. The goal is to search for a value in a corresponding column (D
in this case). Therefore I search in the selected sheet (named after the selected value in the UpdateComboBox
). To be able to search I first select the rownumber corresponding to the Weld showed in RelatedWeldTextBox_i
. This value differs following other input boxes.
The code below is wrong. It creates a String with the for loop: TextBox1
for example. But it starts searching column D
for the String TextBox1
instead of the value presented in this textbox. If I use Weld = Textbox1.Value
The code works but only for Textbox1
of course...
Sub RelatedWeldNegative ()
Dim Weld As String
Dim Bmin As Integer
Dim Bmax As Integer
Dim i As Integer
For i = 1 To 4`
Weld = "Textbox" & i & ".Value"
For Each Cell In ActiveWorkbook.Sheets(UpdateComboBox.Value).Range("C2:C320")
If Cell.Text = Weld Then
SelecRow = Cell.Row
End If
Next
Next i
Bmax = 6
Bmin = ActiveWorkbook.Sheets(UpdateComboBox.Value).Cell(SelecRow, "D")
'follow up with code
End Sub
Thanks in advance,
Miriam