Writing into random cell base on textbox values, Error if textbox have Multiple values only works with single value

petroes

New Member
Joined
Apr 4, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
i'm totally new with VBA and need your help, the problem is i want to select random cells in a given row, as you can see in the picture, the userform have ComboBox X = represent row, TextBox Y=Represent column and CommanButton "Input", i'm stuck with the error when i try to input multiple values separated with comma inside the textbox, as far it only works if the textbox contain a single values within, here is my code :

Private Sub cbInput_Click()

Dim x As Variant
Dim y As Variant

x = cmbBox_X.Value
y = txtBox_Y.Value

With Worksheets.Application.ActiveSheet
.Cells(x, y).Value = "check" '(error in here when i try with multiple values: runtime error ''13''; type mismatch)
End With

End Sub

SSxy2.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi,
welcome to forum

try

VBA Code:
Private Sub cbInput_Click()
    
    Dim x As Variant
    Dim y() As String
    Dim i As Integer
    
    x = Val(cmbBox_X.Value)
    y = Split(txtBox_Y.Value, ",")

    For i = 0 To UBound(y)
        ActiveSheet.Cells(x, y(i)).Value = "check"
    Next
    
End Sub

Dave
 
Upvote 0
Upvote 0
Cross posted



A message to forum cross posters
frankly i didnt know such things like that in web forum, and thanks for the information
 
Upvote 0
Cross posted



A message to forum cross posters
i really didn't know about this rule, so i want ti delete this thread on here
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,538
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top