what am i trying to do here is simply just like the gantt chart i want to write into a cell in range that meet two conditions, but got an error runtime 13: type mismatch, i still can figure it out what is wrong with the code, and can you show me how to loop through each row from column name in worksheet "dtbs"...
here is the workbook that i've been working on....
Option Explicit
Private Sub cbInput_Click()
Dim rg As Range
Dim x As String
Dim yA As Variant
Dim yB As Variant
Dim yC As Variant
Dim yD As Variant
Dim txA As String
Dim txB As String
Dim txC As String
Dim txD As String
Srkp.Activate
Set rg = Range("D9:AH14")
rg.Activate
Selection.VerticalAlignment = xlCenter
Selection.HorizontalAlignment = xlCenter
txA = Sheets("dtbs").Cells(2, 3).Value 'For_S
txB = Sheets("dtbs").Cells(2, 4).Value 'For_I
txC = Sheets("dtbs").Cells(2, 5).Value 'For_T
txD = Sheets("dtbs").Cells(2, 6).Value 'For_C
x = Sheets("dtbs").Cells(2, 2).Value
'============================================
'On Error Resume Next
If InStr(txA, ",") Then
For Each yA In Split(txA, ",")
rg.Cells(x, yA).Value = "S"
Next yA
Else
yA = txA
rg.Cells(x, yA).Value = "S"
End If
'============================================
'On Error Resume Next
If InStr(txB, ",") Then
For Each yB In Split(txB, ",")
rg.Cells(x, Val(yB)).Value = "I"
Next yB
Else
yB = txB
rg.Cells(x, Val(yB)).Value = "I"
End If
'============================================
'On Error Resume Next
If InStr(txC, ",") Then
For Each yC In Split(txC, ",")
rg.Cells(x, Val(yC)).Value = "T"
Next yC
Else
yC = txC
rg.Cells(x, Val(yC)).Value = "T"
End If
'============================================
'On Error Resume Next
If InStr(txD, ",") Then
For Each yD In Split(txD, ",")
rg.Cells(x, Val(yD)).Value = "C"
Next yD
Else
yD = txD
rg.Cells(x, Val(yD)).Value = "C"
End If
cmbBox_Month.Value = cmbBox_Month.Value
cmbBox_X.SetFocus
Unload Me
End Sub
Bookmarks