Same edit to multiple cells.

T

TomAlbert

How do I make the same edit to numerous cells with
different data in each? I need to replace the first
digit in a column of numbers with a zero.
 
F

Frank Kabel

Hi
You may use a macro for this. try
Sub change_rows()
Dim RowNdx As Long
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
For RowNdx = 1 to LastRow
with Cells(RowNdx, "A")
if .value <> "" then
.value = "'0" & mid(.value,2,255)
End If
end with
Next RowNdx
Application.ScreenUpdating = True
End Sub

Note: this will convert the numbers to 'Text'
 
H

Harlan Grove

You may use a macro for this. try
Sub change_rows()
Dim RowNdx As Long
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
For RowNdx = 1 to LastRow
with Cells(RowNdx, "A")
if .value <> "" then
.value = "'0" & mid(.value,2,255)
End If
end with
Next RowNdx
Application.ScreenUpdating = True
End Sub
...

A few things. For generality, it's usually better to make the user select the
cells to be operated upon before running macros as opposed to hardcoding the
range in the macro. Also, the OP likely doesn't want to do this to cells
containing formulas in case such cells are inadvertently selected. Finally,
unlike the MID worksheet function, the 3rd argument to VBA's Mid function is
optional and shouldn't be specified when you want the remainder of the string.


Sub change_rows()
Dim c As Range, f As String

If Not TypeOf Selection Is Range Then Exit Sub

On Error GoTo CleanUp

Application.ScreenUpdating = False

For Each c In Selection
If Not c.HasFormula And c.Formula <> "" Then
c.Formula = "'0" & Mid(c.Formula, 2)
End If
Next c

CleanUp:
Application.ScreenUpdating = True

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top