Replace cell value with zero base of cell value

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

I hope you can help on this please

I want to change the cell values based on another cell value and below is the code I have been trying to modify for this to work
This macro completes the changes but leaves the value in each cell as "FALSE", I need this to be either blank or 0.00 in each cell.

[
With ThisWorkbook.Sheets("Raw Data")
For r = 1 To .Cells(Rows.Count, "AC").End(xlUp).Row
If Cells(r, "AC") = "RS" Then
If .Cells(r, "R") > 0 Then .Cells(r, "R") = .Cells(r, "R") = ""
If .Cells(r, "S") > 0 Then .Cells(r, "S") = .Cells(r, "S") = ""
If .Cells(r, "T") > 0 Then .Cells(r, "T") = .Cells(r, "T") = ""
If .Cells(r, "AA") > 0 Then .Cells(r, "AA") = .Cells(r, "AA") = ""
If .Cells(r, "AB") > 0 Then .Cells(r, "AB") = .Cells(r, "AB") = ""
End If
Next r
End With]
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Kindly try this
VBA Code:
With ThisWorkbook.Sheets("Raw Data")
For r = 1 To .Cells(Rows.Count, "AC").End(xlUp).Row
If Cells(r, "AC") = "RS" Then
If .Cells(r, "R") > 0 Then .Cells(r, "R") = .Cells(r, "R") = """"
If .Cells(r, "S") > 0 Then .Cells(r, "S") = .Cells(r, "S") = """"
If .Cells(r, "T") > 0 Then .Cells(r, "T") = .Cells(r, "T") = """"
If .Cells(r, "AA") > 0 Then .Cells(r, "AA") = .Cells(r, "AA") = """"
If .Cells(r, "AB") > 0 Then .Cells(r, "AB") = .Cells(r, "AB") = """"
End If
Next r
 
Upvote 0
Hi there. Remove the duplicated part of each formula like this:
VBA Code:
With ThisWorkbook.Sheets("Raw Data")
For r = 1 To .Cells(Rows.Count, "AC").End(xlUp).Row
If Cells(r, "AC") = "RS" Then
If .Cells(r, "R") > 0 Then  .Cells(r, "R") = ""
If .Cells(r, "S") > 0 Then  .Cells(r, "S") = ""
If .Cells(r, "T") > 0 Then  .Cells(r, "T") = ""
If .Cells(r, "AA") > 0 Then  .Cells(r, "AA") = ""
If .Cells(r, "AB") > 0 Then  .Cells(r, "AB") = ""
End If
Next r
End With
 
Upvote 0
Use this code.

Code:
Sub text()


With ThisWorkbook.Sheets("Raw Data")
For r = 1 To .Cells(Rows.Count, "A").End(xlUp).Row
If Cells(r, "A") = "RS" Then
If .Cells(r, "R") > 0 Then .Cells(r, "R") = ""
If .Cells(r, "S") > 0 Then .Cells(r, "S") = ""
If .Cells(r, "T") > 0 Then .Cells(r, "T") = ""
If .Cells(r, "AA") > 0 Then .Cells(r, "AA") = ""
If .Cells(r, "AB") > 0 Then .Cells(r, "AB") = ""
End If
Next r
End With

End Sub
 
Upvote 0
Hi All

Can I ask another question please

I want to change this to be able to copy all values in column "T" to column "Q" based on the same criteria

This works at the start but disappears when the loop finishes


[With ThisWorkbook.Sheets("Raw Data")
For s = 1 To .Cells(Rows.Count, "AC").End(xlUp).Row
If Cells(s, "AC") = "RS" Then
If .Cells(s, "T") > 0 Then .Cells(s, "Q") = .Cells(i, "T")
If .Cells(s, "R") > 0 Then .Cells(s, "R") = ""
If .Cells(s, "S") > 0 Then .Cells(s, "S") = ""
If .Cells(s, "T") > 0 Then .Cells(s, "T") = ""
If .Cells(s, "AA") > 0 Then .Cells(s, "AA") = ""
If .Cells(s, "AB") > 0 Then .Cells(s, "AB") = ""
End If
Next s
End With]
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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