excel vba: Replace cell

huiyin9218

Board Regular
Joined
Aug 7, 2018
Messages
53
Hi,

How do I write a code to replace cell that contains specific value. For example, when "0.00E+00" is detected, I would like the cell on the left to replace "0.00E+00"

Column AColumn B
Row 1AB0.00E+00
Row 208.65E+00
Row 3EF0.00E+00
Row 401.85E+00

<tbody>
</tbody>


When "0.00E+00" is detected in column B, cell on the left will replace it. Sample table is shown above and output I wish to obtain is shown in table below.

Column AColumn B
Row 1AB
Row 208.65E+00
Row 3EF
Row 401.85E+00

<tbody>
</tbody>

I would be so grateful for your help.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
ABAB
08.65E+00
EFEF
01.85E+00
this macro has done it
ub Macro4()
'
' Macro4 Macro
' Macro recorded 16/08/2018 by bob
'
'
For j = 1 To 4
If Cells(j, 2) = 0# Then Cells(j, 2) = Cells(j, 1)
Next j
End Sub

<colgroup><col><col><col span="8"></colgroup><tbody>
</tbody>
 
Upvote 0
huiyin9218,

Here is another macro solution for you to consider that will run in the active worksheet.

Code:
Sub huiyin9218()
' hiker95, 08/16/2018, ME1067229
Dim c As Range
Application.ScreenUpdating = False
With ActiveSheet
  For Each c In .Range("B1", .Range("B" & Rows.Count).End(xlUp))
    If c = 0# Then
      c = c.Offset(, -1)
      c.Offset(, -1).ClearContents
    End If
  Next c
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
huiyin9218,

Here is another macro solution for you to consider that will run in the active worksheet.

Code:
Sub huiyin9218()
' hiker95, 08/16/2018, ME1067229
Dim c As Range
Application.ScreenUpdating = False
With ActiveSheet
  For Each c In .Range("B1", .Range("B" & Rows.Count).End(xlUp))
    If c = 0# Then
      c = c.Offset(, -1)
      c.Offset(, -1).ClearContents
    End If
  Next c
End With
Application.ScreenUpdating = True
End Sub

This works for me. Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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