View Full Version : Solved: Changing text in multiple cells
FantasticJac
09-27-2007, 06:16 AM
I'm trying to change every cell in a selected cell area to add ".pwf" to the end of the text string. I tried to set the macro up like a normal cell formatting change (ie, text color or bold) but it will only change the top cell in the selection. Is there a way to change it in all selected cells??? I know this is probably beginner stuff, but that's what I am.... :banghead: Any help would be great! This is all I have so far. Thanks!
Sub test()
'
' test Macro
' Macro recorded 9/27/2007
'
' Keyboard Shortcut: Ctrl+t
'
ActiveCell.FormulaR1C1 = ActiveCell.FormulaR1C1 + ".pwf"
End Sub
Bob Phillips
09-27-2007, 06:25 AM
For Each cell In selection
cell.Value = cell.Value & ".pwf"
Next cell
FantasticJac
09-27-2007, 06:59 AM
Thanks!! What if I want to select a column (Say "E" for example) and only change the fields that have text in them and leave the blank ones blank?
Bob Phillips
09-27-2007, 08:18 AM
For Each cell In Columns(5)
If cell.Value <> "" Then
If Not IsNumeric(cell.Value) Then
cell.Value = cell.Value & ".pwf"
End If
End If
What about if it has a formula?
FantasticJac
09-27-2007, 11:18 AM
I can't get this to work. I added a "Next cell" to finish the For/Next, but it doesn't like the "If cell.Value <> "" Then. Complains about a type mismatch. I've tried to suppliment several different changes to tweak it but nothing is working. The best I can do is erase everything in column 5.
Bob Phillips
09-27-2007, 11:27 AM
Sorry, my bad
For Each cell In Columns(5).Cells
If cell.Value <> "" Then
If Not IsNumeric(cell.Value) Then
cell.Value = cell.Value & ".pwf"
End If
End If
Next cell
FantasticJac
09-27-2007, 11:35 AM
I swear I tried that about five times and it didn't work. Now it does. Hmmm... Thanks!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.