Hi guys,
Im having trouble figuring this out. I have 2 comboboxes and 7 textboxes. What it does combobox1(cboagent) will show all the names (Range B)which is already filtered in sheet "Report". Once a name is selected combobox2(cbodatadate) will show all the dates (Range C) that corresponds to the name selected. What im having trouble is how will I transfer the data from the cell to my textboxes.
Let me give an example just to make it clear:
Combo1 Combo2
Mike - 04/12/2013
- 05/15/2013
- 02/15/2014 <-- lets say I select this
- 03/15/2015
textbox1 = cell C, textbox2 = cell D, textbox3 = cell E, textbox4 = cell F,
textbox5 = cell G, textbox6 = cell H, textbox7 = cell I
Now if in case I change the date textboxes value will also change.
Really having trouble with this. Hope somebody can help me out
I've used this formula to filter the name and dates (myData):
=OFFSET('Report'!$B$2,0,0,COUNTA('Report'!$B:$B),1)
frmcoaching:
Option Explicit
Dim FArray As Variant
Dim DataList As Range, cel As Range, Rng As Range
Dim MyList As String
Dim ws As Worksheet
Private Sub UserForm_Initialize()
cboagent.Enabled = True
txtdate.Text = Date
Me.txtsupname.Text = frmlogin.cbousername.Text
ThisWorkbook.Sheets("Report").Activate
Dim Found As Long, i As Long
Sheets("Report Coaching").AutoFilterMode = False
MyList = "myData"
Set DataList = Range(MyList).Columns(1)
DataList.Select
Set DataList = Selection
ReDim FArray(DataList.Cells.Count)
i = -1
For Each cel In DataList
On Error Resume Next
Found = Application.WorksheetFunction.Match(cel, FArray, 0)
If Found > 0 Then GoTo Exists
i = i + 1
FArray(i) = cel
Exists:
Found = 0
Next
ReDim Preserve FArray(i)
Call BubbleSort(FArray)
cboagent.ListRows = i + 1
cboagent.List() = FArray
End Sub
Private Sub cboagent_Change()
Flag = True
cbodatadate.Clear
Set ws = Sheets("Report")
With ws
If Not ActiveSheet.AutoFilterMode Then
ActiveSheet.Range("B2").AutoFilter
End If
.Range(("B2"), .Range("B2").End(xlDown)).AutoFilter Field:=2, Criteria1:=Me.cboagent.Value
Set Rng = .Range("myData").Columns(2).SpecialCells(xlCellTypeVisible)
Set Rng = .Range("myData").Columns(2).SpecialCells(xlCellTypeVisible)
For Each cel In Rng
With Me.cbodatadate
.AddItem cel.Offset(0, 0).Value
End With
Next cel
End With
Flag = False
End Sub
Private Sub cbodatadate_Click()
End Sub
Private Sub cbodatadate_Change()
End Sub
Private Sub cmdlogout_Click()
End Sub
Private Sub cmdrefresh_Click()
Unload Me
frmcoaching.Show
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
MsgBox "Sorry you must use the CLOSE Button"
Cancel = True
End If
End Sub
Sub BubbleSort(MyArray As Variant)
Dim First As Integer
Dim Last As Integer
Dim i As Integer
Dim j As Integer
Dim Temp As String
First = LBound(MyArray)
Last = UBound(MyArray)
For i = First To Last - 1
For j = i + 1 To Last
If MyArray(i) > MyArray(j) Then
Temp = MyArray(j)
MyArray(j) = MyArray(i)
MyArray(i) = Temp
End If
Next j
Next i
End Sub
Display More