# Compare letters on Vba

#### sinanvarann

##### New Member
Hey guys I have a word like "abadi" and i want to enter a new word like "abc". If this abc letter a b and c are used on this word for once. Output should be at B1 cell. "abadi" has not "c" thats why its shouldn't work.
I coded it but there "abadi" consist 2 times "a" letter thats why counter takes "a" second time its shouldn't be. If i found "a" letter pass it in the another loop. I don't need another ways of solution I need only extract second same letter.

### Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

#### Saurabhj

##### Active Member
Hi,

With few examples, can you share the expected output?

Thanks,
Saurabh

#### Fluff

##### MrExcel MVP, Moderator
Maybe
VBA Code:
``````Sub sinanvarann()
Dim Txt As String
Dim i As Long

Txt = InputBox("Enter any word")
For i = 1 To Len(Txt)
If InStr(1, Cells(1, 1), Mid(Txt, i, 1), vbTextCompare) = 0 Then
Exit Sub
End If
Next i
Cells(1, 2) = Cells(1, 1)
End Sub``````

#### sinanvarann

##### New Member
Hi,

With few examples, can you share the expected output?

Thanks,
Saurabh

#### Attachments

• share.jpg
85.2 KB · Views: 1

#### sinanvarann

##### New Member

Maybe
VBA Code:
``````Sub sinanvarann()
Dim Txt As String
Dim i As Long

Txt = InputBox("Enter any word")
For i = 1 To Len(Txt)
If InStr(1, Cells(1, 1), Mid(Txt, i, 1), vbTextCompare) = 0 Then
Exit Sub
End If
Next i
Cells(1, 2) = Cells(1, 1)
End Sub``````
Thank you but I cannot use another ways. Its an assignment thats why I can use only for, do while , if else , goto commands. If you try to fix my mistake in that file or adding somethings. I will be happy.

#### Fluff

##### MrExcel MVP, Moderator
Its an assignment
In that case you should have said so in your original post. We are not here to do your homework for you, but will happily point you in the right direction.
If you try to fix my mistake
You haven't posted any code for us to look at.

#### sinanvarann

##### New Member
In that case you should have said so in your original post. We are not here to do your homework for you, but will happily point you in the right direction.

You haven't posted any code for us to look at.
Okey thank you. So can i get any help to fix my program speed. I finished the code finally. But Its so slow. Excel freezing. I tried to use DoEvent after for loop. Still freezing.

#### Fluff

##### MrExcel MVP, Moderator
Can you please post the code you are using.

Replies
9
Views
176
Replies
1
Views
58
Replies
20
Views
139
Replies
1
Views
218
Replies
1
Views
159

1,130,381
Messages
5,641,827
Members
417,240
Latest member
pjohnsonexcel

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back