View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
keiji kounoike keiji kounoike is offline
external usenet poster
 
Posts: 199
Default how to program this?


Copy every line below into your UserForm module and look whether it work
or not. CBlist = Array("One", "Two", "Three") is a list ordered by priority.


Dim CBlist

Private Sub UserForm_Initialize()
CBlist = Array("One", "Two", "Three") '<<==Change to your data
ComboBox1.List = CBlist
ComboBox2.List = CBlist
End Sub

Private Sub ComboBox1_Change()
If MyStrCmp(ComboBox1.Value, ComboBox2.Value) 0 Then
TextBox1.Text = "Discrepancy"
Else
TextBox1.Text = ""
End If
End Sub

Private Sub ComboBox2_Change()
If MyStrCmp(ComboBox1.Value, ComboBox2.Value) 0 Then
TextBox1.Text = "Discrepancy"
Else
TextBox1.Text = ""
End If
End Sub

Function MyStrCmp(ByVal Fstr As String, ByVal Nstr As String) As Integer
Dim F1, N1
On Error GoTo ex:
If Fstr < "" And Nstr < "" Then
F1 = Application.Match(Fstr, CBlist, 0)
N1 = Application.Match(Nstr, CBlist, 0)
If N1 < F1 Then
MyStrCmp = 1
ElseIf N1 = F1 Then
MyStrCmp = 0
Else
MyStrCmp = -1
End If
Else
MyStrCmp = -2
End If
Exit Function
ex:
MyStrCmp = -3
End Function

Keiji

sam wrote:
Thanks for your help keiji, Yes i think you are rite, if string in B has a
higher importance then discrepancy will be populated in C.
I dont want C to say Discrepancy every time the values are different. There
are certain combinations that will show discrepancy.

For Eg:
Lets say Values in A and B a One, Two, Three

So if we select One for A and Two for B, then C is blank
if we select Two for A and Three for B, then also C is blank
But iif we select Two for A and One for B then C is populated with
Discrepancy.

Certain values in A and B dropdown have priority over other, If a better
value is selected for A then C is left blank, But if B has better value then
C is populated with Discrepancy.

Thanks a Lot in Advance

"keiji kounoike" <"kounoike AT mbh.nifty." wrote:

Do you mean 'Discripancy' shows in C only if the string in B sorts ahead
of the string in A? if so and all is in UserForm, Does this one works?

Private Sub ComboBox1_Enter()
ComboBox1.List = Array("audit", "edit", "compile")
End Sub

Private Sub ComboBox1_Change()
If ComboBox1.Value ComboBox2.Value Then
Me.TextBox1.Text = "Discrepancy"
Else
Me.TextBox1.Text = ""
End If
End Sub

Private Sub ComboBox2_Enter()
ComboBox2.List = Array("audit", "edit", "compile")
End Sub

Private Sub ComboBox2_Change()
If ComboBox1.Value ComboBox2.Value Then
TextBox1.Text = "Discrepancy"
Else
TextBox1.Text = ""
End If
End Sub

Keiji

sam wrote:
Thanks a lot for your help,

In my case I have two columns A and B as dropdown menus and both have same
values as follows:
edit, audit, compile.

Now, If B has 'audit' as its value and A has 'edit' as its value I want to
populate C with 'Descripancy', But if B is audit and A is also audit then C
has to be blank.
Also if B is edit and A is audit leave C as blank.

The values in A and B i gave above are just a few values from the list that
I have, But this is the way how it works. A and B have criterias listed in a
drop down menu and selecting, certain value for A and B would display
'Discrepancy' in C.

I hope it is clear now.

Thanks in Advance


"future_vba_expert" wrote:

Sam,

For your first question, I would just put something like this in col C:

=(IF(A1=B1,"yes","no"))

You can copy and paste into as many cells as you need in col C.

As for your second question, the '' and '<' use the alphabetical order to
determine what is greater or less than for text. So 'aa' is less than 'ab',
just like in the phone book. The formula in C1 would look like this:

=(IF(A1<B1,"1"," "))

ps. In your example, 'lion' is not less than 'cat', so cell C1 would display
spaces.



=
--
future_vba_expert


"sam" wrote:

I have a sheet with 3 columns: A, B, C
A is a dropdown with following values
compile, edit, audit

B is a dropdown and has the same values as A
compile, edit, audit

C is a text box that auto populates with either "Yes" or "No" depending on
what we select for A and B

If I select same values for A and B then I want a Yes for C
If I select different values for A and B then I want a No

Also, I have seen an IF statement in a cell that has text values.

The IF statement compares two cells with text values but has a '' and a '<'
comparison made. For eg, If 'lion' < 'cat' then display '1' and so on.
My question is, How can we make such a comparison of or < with a text value?

Thanks in Advance.