If last character of cell <> ) then add (text)

Hyflex

New Member
Joined
Mar 28, 2011
Messages
40
I'm looking for a macro to do the following:


If cell in Column O (from top to bottom) does NOT end in ) then add (text) to the end...

Kin (Let)
Led
Fen

Cho De (Let)
Lem
Kop (Let)

^ The bold lines above do NOT end in a ) so they need (Let) to be added
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This should do what you asked for...

Code:
Sub AddParens()
  Dim X As Long
  Application.ScreenUpdating = False
  For X = 1 To Cells(Rows.Count, "A").End(xlUp).Row
    If Right(Cells(X, "A").Value, 1) <> ")" Then Cells(X, "A").Value = Cells(X, "A").Value & " (Let)"
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Code:
Sub test()
Dim c As Range
For Each c In Range("O1:O" & Range("O" & Rows.Count).End(xlUp).Row)
    If Right(c, 1) <> ")" Then c = c & " (LET)"
Next
End Sub
 
Upvote 0
Try this formula. should work. then just copy the values. let me know it that worked for you.

IF(RIGHT(A2,5)="(let)",a1,A2 & " " & "(let)")

ryan
 
Upvote 0
just recored the macro with a double click on the bottom right of the cell after you insert the formula and it should work everytime as long as you dont have blank cells in the data
 
Upvote 0
If cell in Column O....
Sorry about my previous posting... I read right over your "Column O" statement and made my code for Column A instead. Here is my code with the correct column reference...

Code:
Sub AddParens()
  Dim X As Long
  Application.ScreenUpdating = False
  For X = 1 To Cells(Rows.Count, "O").End(xlUp).Row
    If Right(Cells(X, "O").Value, 1) <> ")" Then Cells(X, "O").Value = Cells(X, "O").Value & " (Let)"
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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