PDA

View Full Version : Solved: How to find the same numbers between two numbers



fanjy
10-11-2007, 07:10 AM
Hi,everyone!
My question:
the following data is in my sheet.
A B C D E
234 3487 34 2 87
the data in column A is 234,column B is 3487.Now,
(1)I want to get the data(34) in column C is the same numbers between column A and column B.
(2)I want to get the data in column D(2) is the different numbers between column A and column B.
(3)I want to get the data in column E(87) is the different numbers between column B and column A.
My English is bad,but I need your help,thanks!

RonMcK
10-11-2007, 10:23 AM
Hi,everyone!
My question:
the following data is in my sheet.
A B C D E
234 3487 34 2 87
the data in column A is 234,column B is 3487.Now,
(1)I want to get the data(34) in column C is the same numbers between column A and column B.
(2)I want to get the data in column D(2) is the different numbers between column A and column B.
(3)I want to get the data in column E(87) is the different numbers between column B and column A.
My English is bad,but I need your help,thanks!

fanjy,

Do the digits found in both Col A and Col B need to be contiguous (grouped together) and appear in the same order in both numbers, like yours are in your example?

How would you evaluate each of the following cases? (I'm using the same digits

A B C D E
234 3487 34 2 87 (your case)
234 4387 ? ? ?
324 3487 ? ? ?
423 8374 ? ? ?


Thanks,

Ron
Orlando, FL

fanjy
10-11-2007, 05:39 PM
Hi,RonMck,
It is the first case.
A B C D E
234 3487 34 2 87

mdmackillop
10-12-2007, 06:00 AM
Will you explain the logic that gives results in D & E.
Maybe if you posted a few examples in a workbook, with explanation, things would be clearer

MachaMacha
10-12-2007, 01:56 PM
Sorry your explanation was not to clear is this what you are looking for?

fanjy
10-12-2007, 07:27 PM
MachaMacha,Please forgive me for my bad English.
See:

fanjy
10-12-2007, 07:36 PM
Or:
I want to find the same string in two strings.For example,
Fisrt string:asdf
Second string:sdfret
result:sdf

mdmackillop
10-13-2007, 01:43 AM
Fanjy,
Please respond FULLY to post #4 (and post #2), I can't see any logic that will allow me to do this on a set of numbers.

fanjy
10-13-2007, 08:08 PM
Sorry.Now I only need get the result in Column C.
Thank you for your patient!

mdmackillop
10-14-2007, 01:34 AM
As you won't answer questions, I'm signing out of this as a pointless exercise.

fanjy
10-28-2007, 01:54 AM
my code:
Sub SeparateNumber()
Dim strFirst As String
Dim strResult As String
Dim StartNum As Integer
Dim EndNum As String
Dim i As Integer, j As Integer
strFirst = Left(Range("B1"), 1)
StartNum = InStr(1, Range("A1"), strFirst)
j = 1
For i = StartNum To Len(Range("A1"))
EndNum = Mid(Range("A1"), i, 1)
If EndNum = Left(Range("B1"), j) Then
j = j + 1
End If
Next i
If j > 1 Then
strResult = Mid(Range("A1"), StartNum, i - 1)
End If
'data in C1
Range("C1").Value = strResult
'data in D1
Range("D1").Value = Left(Range("A1"), StartNum - 1)
'data in E1
Range("E1").Value = Right(Range("B1"), Len(Range("B1")) - j)
End Sub