Can anyone help correct my code please?
I'd like to copy only the first 5 values in any given selection to 5 textboxes on a userform. I've tried to create an array from selection and an array for the textboxes but I'm not sure if textboxes can be written into an array. I converted selection to a range as well as an array as I couldn't see another way of assigned value to the textboxes otherwise.
Ideally I'd like to add an If statement to handle a selected range that is more than 1 column as well as the possibility of a single cell selection.
Am struggling with this and it's a bit of a mess. Any help much appreciated.
I'd like to copy only the first 5 values in any given selection to 5 textboxes on a userform. I've tried to create an array from selection and an array for the textboxes but I'm not sure if textboxes can be written into an array. I converted selection to a range as well as an array as I couldn't see another way of assigned value to the textboxes otherwise.
VBA Code:
Sub Rapid_Search()
Dim txtbox(1 To 5), TargetArr As Variant
Dim SourceRng, cel As Range
Dim i, j As Long
Set SourceRng = Application.ActiveWindow.Selection
TargetArr = ActiveWorkbook.ActiveSheet.Selection.Value
txtbox(1) = frmRapid1.txtNum1
txtbox(2) = frmRapid1.txtNum2
txtbox(3) = frmRapid1.txtNum3
txtbox(4) = frmRapid1.txtNum4
txtbox(5) = frmRapid1.txtNum5
For Each cel In SourceRng
For i = LBound(TargetArr) To (TargetArr(5))
For j = txtbox(1) To txtbox(5)
txtbox.Text = cel.Value 'txtbox flagged as invalid qualifier on this line
Next
Next
Next
End Sub
Ideally I'd like to add an If statement to handle a selected range that is more than 1 column as well as the possibility of a single cell selection.
Am struggling with this and it's a bit of a mess. Any help much appreciated.