for each cell in a column that has text, add suffix "Jones"

keithmct

Active Member
Joined
Mar 9, 2007
Messages
256
Office Version
  1. 2021
Platform
  1. Windows
hello all, this one is pretty self-explanatory. I have a button I want to press and search range S14:S40 and if there is any text in there add something to the end like A or Jones.
that will enable me to redirect my spreadsheet to do an alternate calculation which I should have under control.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Code:
Option Explicit


Sub Jones()
    Dim c As Range, rng As Range
    Set rng = Range("s14:s40")
    Application.ScreenUpdating = False
    For Each c In rng
        If Application.WorksheetFunction.IsText(c) Then
            c = c & " Jones"
        End If
    Next c
    Application.ScreenUpdating = True
    MsgBox "Actions Completed"
End Sub
 
Upvote 0
Here is another macro that you can consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub Jones()
  [S14:S50] = [IF(ISTEXT(S14:S50),S14:S50&" Jones",IF(S14:S50="","",S14:S50))]
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
thank you both. I went with Rick's elegant suggestion solely due to length, although I understand Alan's much better.
If I was to change my button to a toggle button to revert to the original, i.e. take Jones off the end, what would that look like?
 
Upvote 0
If I was to change my button to a toggle button to revert to the original, i.e. take Jones off the end, what would that look like?
This macro code will toggle between adding Jones if it is not there and removing it if it is there...
Code:
[table="width: 500"]
[tr]
	[td]Sub Jones()
  [S14:S50] = [IF(RIGHT(S14:S50,6)=" Jones",LEFT(S14:S50,LEN(S14:S50)-6),IF(ISTEXT(S14:S50),S14:S50&" Jones",IF(S14:S50="","",S14:S50)))]
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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