-
combox box criteria
I have the userform combo box
and two excel called user and ownr
user have columns
DEPTCODE** USERID USERNAME GROUP ENVIRONMENT
owner has so many columns
but the same in user have also COLUMN D, F G DEPTCODE, ENVIRONMENT, USERID
When i select deptcode from combo box,
select from usersheet whoever userid corresponding group and
from ownr sheet whoever correspondign matchwith userid, deptcode and group
columnn i, j
here is the code
but still difficult from user sheet
here is the code from combo box click
Code:
Private Sub ComboBox1_Click()
Dim xlsheetUserid As Object
Dim UserInfoObject As Object
strInputDate = TextBox1.Value
date_Switch = 0
strSheetName = ActiveSheet.Name
Set UserInfoObject = GetObject(strWBuseridInformation)
Set xlsheetManagersOwners = UserInfoObject.Worksheets("ownr")
intCriteria = ComboBox1.ListIndex
strCriteria = ComboBox1.List(intCriteria)
x = strCriteria
If Not IsEmpty(strCriteria) Or strCriteria <> "" Then ' >= 1 Then
If IsEmpty(strInputDate) Or strInputDate = "" Then
MsgBox "Respond-By Date cannot be blank.", vbInformation, "Security_Verification_Error"
ComboBox1.ListIndex = -1
TextBox1.SetFocus
Exit Sub
Else
checkTheDate strInputDate, date_Switch
If date_Switch > 0 Then
TextBox1.SetFocus
Exit Sub
End If
End If
End If
'Turn on autofiltermode if it is off.
If Not Worksheets("ownr").AutoFilterMode Then
Worksheets("ownr").Select
Selection.AutoFilter
End If
'Sort by DEPT CODE, then USER LOGONID/ ENVIRONMENT
Worksheets("ownr").Range("A1:N3000").Sort _
key1:=Worksheets("ownr").Range("D1"), _
Order1:=xlAscending, Header:=xlYes, _
Key2:=Worksheets("ownr").Range("G1"), _
Order2:=xlAscending, Header:=xlYes, _
Key3:=Worksheets("ownr").Range("F1"), _
Order3:=xlAscending, Header:=xlYes
'Filters the data on the deptcode column
Worksheets("ownr").Range("DeptCodeRange").AutoFilter _
Field:=4, _
Criteria1:=strCriteria
With Worksheets("ownr").Range("DeptCodeRange")
.Select
intRowcount = Selection.Rows.Count
Set c = .Find(x, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
If c Is Nothing Then
firstAddress = c.Address
Set c = .FindNext(x)
Else
nextAddress = c.Address
strAlpha = Mid(nextAddress, 2, 1)
strNum = Mid(nextAddress, 4)
strCellLocation = strAlpha & strNum
Worksheets("ownr").Range(strCellLocation).Select
strCellLocationHold = strCellLocation
End If
End With
usrOwnerDeptCode = Selection.Value
usrResource = Selection.Offset(0, 1).Value
usrOwnerEnviron = Selection.Offset(0, 2).Value
usrOwnerID = Selection.Offset(0, 3).Value
strUserOwnerIDHold = usrOwnerID
usrOwnerName = Selection.Offset(0, 4).Value
strUserOwnerNameHold = usrOwnerName
intComma = InStr(1, usrOwnerName, ",")
usrOwnerDataSet = Selection.Offset(0, 5).Value
usrOwnerDesc = Selection.Offset(0, 6).Value
usrAuthority = Selection.Offset(0, 7).Value
strCurrAddr = Selection.Address
Myswitch = 0
Select Case strMenuItemSelect
Case "USER ID"
With Worksheets("ownr").Range("DeptCodeRange")
.Select
Set c = .Find(x, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
If c Is Nothing Then
Set c = .FindNext(c)
strGetAddresses = c.Address
strAlpha = Mid(strGetAddresses, 2, 1)
strNum = Mid(strGetAddresses, 4)
strCellLocation = strAlpha & strNum
Worksheets("ownr").Range(strCellLocation).Select
Else
Do
If IsEmpty(usrOwnerName) Or usrOwnerName = "" Then
If IsEmpty(usrOwnerDeptCode) Or usrOwnerDeptCode = "" Then
MsgBox "Program Finished", , "Security_Verification"
Else
GoTo ReadNextRec
End If
End
Else
instrComma = InStr(1, usrOwnerName, ",")
If instrComma > 1 Then
strCommaData = UCase(Trim(Mid(usrOwnerName, 1, instrComma - 1)))
Else
strCommaData = UCase(Trim(Mid(usrOwnerName, 1)))
GoTo ReadNextRec
End If
strEmailSentCheck = c.Offset(0, 10).Value
If IsEmpty(strEmailSentCheck) Or strEmailSentCheck = "" Then
TopOne: strAddr = c.Address
usrOwnerEnviron = c.Offset(0, 2).Value
usrOwnerID = c.Offset(0, 3).Value
usrOwnerName = c.Offset(0, 4).Value
usrOwnerDataSet = c.Offset(0, 5).Value
usrOwnerDesc = c.Offset(0, 6).Value
usrAuthority = c.Offset(0, 7).Value
usrOwnerDeptCode = c.Value
intTmpSpace = InStr(1, usrOwnerDataSet, " ")
tmpOwnerDataset = Mid(usrOwnerDataSet, intTmpSpace + 1)
If usrOwnerID = strUserOwnerIDHold Then
strInputUserid = "(" & strUserOwnerIDHold & ")"
If usrOwnerEnviron = "SCC" Then
PutSpaceLength tmpOwnerDataset, usrOwnerDesc, strSpaces, strAccesSpaces
strOwnerDataSet = tmpOwnerDataset & strSpaces & usrAuthority
strDatasetSCC = strDatasetSCC + strOwnerDataSet & "<br>"
Else
PutSpaceLength tmpOwnerDataset, usrOwnerDesc, strSpaces, strAccesSpaces
strOwnerDataSet = tmpOwnerDataset & strSpaces & usrAuthority
strDatasetMCC = strDatasetMCC + strOwnerDataSet & "<br>"
End If
c.Offset(0, 10).Value = "Y"
c.Offset(0, 11).Value = Format(Now, "mmm dd/yyyy")
c.Offset(0, 12).Value = Format(strInputDate, "mmm dd, yyyy")
strUserOwnerIDHold = usrOwnerID
strUserOwnerNameHold = usrOwnerName
strUserOwnerHoldDataSet = tmpOwnerDataset
strSpaces = ""
strAccesSpaces = ""
Else
intNumRecRead = intNumRecRead + 1
OutputEmail strUserOwnerIDHold, strUserOwnerNameHold, strDatasetSCC, strDatasetMCC
strDatasetMCC = ""
strDatasetSCC = ""
strUserOwnerIDHold = usrOwnerID
strUserOwnerNameHold = usrOwnerName
strUserOwnerHoldDataSet = tmpOwnerDataset
strUserAuthority = usrAuthority
GoTo TopOne
End If
Else
intSent = 1 ' MsgBox "Email Already Sent"
End If
End If
ReadNextRec:
Set c = .FindNext(c)
strGetAddresses = c.Address
strAlpha = Mid(strGetAddresses, 2, 1)
strNum = Mid(strGetAddresses, 4)
strCellLocation = strAlpha & strNum
Worksheets("ownr").Range(strCellLocation).Select
usrOwnerDeptCode = c.Value
usrOwnerID = c.Offset(0, 3).Value
usrOwnerName = c.Offset(0, 4).Value
If strCellLocationHold = strCellLocation Then
If intSent = 1 Then
strUsrSent = LCase(Mid(strMenuItemSelect, 1, 4))
MsgBox "Email already sent to this " & strUsrSent & " ", , "Security_Verification"
'Worksheets("ownr").AutoFilterMode = False
Exit Sub
Else
OutputEmail strUserOwnerIDHold, strUserOwnerNameHold, strDatasetSCC, strDatasetMCC
'Worksheets("ownr").AutoFilterMode = False
Exit Sub
End If
End If
Loop
End If
End With