C
Chris
Hello, I have a code that works if I got everything in 1 sheet.
However I want to split it into 3 sheets and still make it work.
Example (1 sheet): http://oi58.tinypic.com/28ahwk9.jpg
Example (3 sheets)
Sheet 1: http://oi62.tinypic.com/2qa1lhd.jpg
Sheet 2: http://oi60.tinypic.com/1ih9jr.jpg
Sheet 3: http://oi60.tinypic.com/2q35ef9.jpg
The code that is working for the first example is:
I tried to change it to the 3-sheets-solution, but it's not working. (Combobox4 is now called Combobox1)
The problem seems to be that Excel cannot get the list of the combobox. What am I doing wrong here?
Thanks a lot.
However I want to split it into 3 sheets and still make it work.
Example (1 sheet): http://oi58.tinypic.com/28ahwk9.jpg
Example (3 sheets)
Sheet 1: http://oi62.tinypic.com/2qa1lhd.jpg
Sheet 2: http://oi60.tinypic.com/1ih9jr.jpg
Sheet 3: http://oi60.tinypic.com/2q35ef9.jpg
The code that is working for the first example is:
Code:
Option Explicit
Private Sub ComboBox4_Change()
Dim arrCode() As Variant
Dim arrList As Variant
Dim strCode As String
Dim Res As Variant
Dim idx As Long
Dim I As Long
Dim J As Long
Dim cnt As Long
arrList = ComboBox4.List
For I = LBound(arrList) To UBound(arrList)
arrList(I, 0) = CStr(arrList(I, 0))
Next I
idx = ComboBox4.ListIndex
cnt = 1
If idx <> -1 Then
For I = Len(ComboBox4.List(idx)) To 2 Step -1
ReDim Preserve arrCode(1 To 3, 1 To cnt)
strCode = Left(ComboBox4.List(idx), I)
Res = Application.Match(strCode, arrList, 0)
If Not IsError(Res) Then
For J = 1 To 3
arrCode(J, cnt) = IIf(Range("A" & Res + 1).Offset(, J).Value = "YES", strCode, "-")
Next J
cnt = cnt + 1
End If
Next I
End If
If cnt > 1 Then
Range("F13", Range("F13").End(xlDown).Offset(, 2)).ClearContents
With Range("F13").Resize(UBound(arrCode, 2), UBound(arrCode))
.NumberFormat = "@"
.Value = Application.Transpose(arrCode)
End With
End If
End Sub
I tried to change it to the 3-sheets-solution, but it's not working. (Combobox4 is now called Combobox1)
Code:
Option Explicit
Private Sub ComboBox1_Change()
Dim arrCode() As Variant
Dim arrList As Variant
Dim strCode As String
Dim Res As Variant
Dim idx As Long
Dim I As Long
Dim J As Long
Dim cnt As Long
arrList = Worksheets("Choose").ComboBox1.List
For I = LBound(arrList) To UBound(arrList)
arrList(I, 0) = CStr(arrList(I, 0))
Next I
idx = Worksheets("Choose").ComboBox1.ListIndex
cnt = 1
If idx <> -1 Then
For I = Len(Worksheets("Choose").ComboBox1.List(idx)) To 2 Step -1
ReDim Preserve arrCode(1 To 3, 1 To cnt)
strCode = Left(Worksheets("Choose").ComboBox1.List(idx), I)
Res = Application.Match(strCode, arrList, 0)
If Not IsError(Res) Then
For J = 1 To 3
arrCode(J, cnt) = IIf(Range("A" & Res + 1).Offset(, J).Value = "YES", strCode, "-")
Next J
cnt = cnt + 1
End If
Next I
End If
If cnt > 1 Then
With Sheets("Calculations")
Range("F13", Range("F13").End(xlDown).Offset(, 2)).ClearContents
With Range("F13").Resize(UBound(arrCode, 2), UBound(arrCode))
.NumberFormat = "@"
.Value = Application.Transpose(arrCode)
End With
End With
End If
End Sub
The problem seems to be that Excel cannot get the list of the combobox. What am I doing wrong here?
Thanks a lot.