ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change a cell based on current content. (https://www.excelbanter.com/excel-programming/388689-change-cell-based-current-content.html)

Mahnian

Change a cell based on current content.
 
I have a sheet full of numbers, intermixed with other data, and need to
change certain cells based on a single criteria.

If the cell contains the character : then I need to add 0: to the beginning
of the current string in that cell.

Can anyone help me with a concise bit of code that will search one sheet and
change those selected cells?

Thank you in advance.


Gary''s Student

Change a cell based on current content.
 
Sub colonate()
Dim s As String
For Each r In ActiveSheet.UsedRange
s = r.Value
If InStr(s, ":") 0 Then
r.Value = "0:" & s
End If
Next
End Sub

--
Gary''s Student - gsnu200718


Tom Ogilvy

Change a cell based on current content.
 
Sub AAA()
Dim cell As Range
For Each cell In Selection.SpecialCells(xlConstants, xlTextValues)
Debug.Print cell.Address, cell.Text
If InStr(1, cell.Value, ":", vbTextCompare) Then
cell.Value = "'0:" & cell.Value
End If
Next
End Sub

--
Regards,
Tom Ogilvy




"Mahnian" wrote:

I have a sheet full of numbers, intermixed with other data, and need to
change certain cells based on a single criteria.

If the cell contains the character : then I need to add 0: to the beginning
of the current string in that cell.

Can anyone help me with a concise bit of code that will search one sheet and
change those selected cells?

Thank you in advance.



All times are GMT +1. The time now is 01:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com