Function doesnt working

cvelle89

New Member
Joined
Aug 6, 2014
Messages
11
Hello.
I want from each cell in range A:A, to check the last letter, and if it is an "a" letter to substitute with letter "e" and to enter it in Cell (B & i)

here is the working code for all other letter except this letter "a" at the end

Code:
Sub stov()

Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("A" & Rows.Count).End(xlUp).Row




For i = 1 To LR
    With Range("A" & i)
    If Right(.Value, 1) = "o" Then Cells(i, 2).Value = Left(.Value, Len(.Value) - 1) & "a"    'genitiv od koga?od cega?
    If Right(.Value, 1) = "a" Then Cells(i, 2).Value = Left(.Value, Len(.Value)-1) & "e"
      ' If Right(.Value, 1) = "n" Then Cells(i, 2).Value = Left(.Value, Len(.Value)) & "a"
     '   If Right(.Value, 1) = "v" Then Cells(i, 2).Value = Left(.Value, Len(.Value)) & "a"
           '  If Right(.Value, 1) = "e" Then Cells(i, 2).Value = Left(.Value, Len(.Value) - 1) & "a"
     '   If Right(.Value, 1) = "r" Then Cells(i, 2).Value = Left(.Value, Len(.Value)) & "a"
     '   If Right(.Value, 1) = "b" Then Cells(i, 2).Value = Left(.Value, Len(.Value) - 1) & "a"
    If Right(.Value, 1) = "m" Then Cells(i, 2).Value = Left(.Value, Len(.Value)) & "a"
     '   If Right(.Value, 1) = "e" Then Cells(i, 2).Value = Left(.Value, Len(.Value) - 1) & "a"
         
        ' If Right(.Value, 1) = "j" Then Cells(i, 2).Value = Left(.Value, Len(.Value)) & "a"
        
    End With
    
    With Range("B" & i)
    
       ' If Right(.Value, 1) = Right(.Value, 2) Then Cells(i, 3).Interior.Color = RGB(255, 0, 0)
    
    End With
    
Next i
Application.ScreenUpdating = True
End Sub

Thanks!
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Your code for "a" just says len(.value). Needs to be len(.value)-1
 
Upvote 0
yeah, I've noticed that, I edit my code here on this topic as well as in VBA. The result is the same. All other functions in the code are doing just fine... this so buggy :)
 
Upvote 0
If the code finds 'blua' in column A it will put 'blue' in column B of the same row. Is that what you think is supposed to happen?
 
Upvote 0
Your code does exactly that when I run it (with the correction steve pointed out needing the -1 after the LEN)
 
Upvote 0
on my machine, it runs code for every other function quite well..except for the **** "a" :)

Ok, thanks..I will try on another machine or to restart the pogram.

Thanks again
 
Upvote 0
Enter the cell where you think it isn't working. Test it for trailing spaces. Then of course right() would produce a space not 'a'.
 
Upvote 0
One thing that might trip it up is that VBA tends to be Case Sensitive.

So if you had say ALOHA
Then = "a" would be false.

Try
If Lcase(Right(.Value, 1)) = "a" Then
 
Upvote 0

Forum statistics

Threads
1,206,761
Messages
6,074,786
Members
446,088
Latest member
Koustubh12

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top