Replace when cell isblank

sitzalke

New Member
Joined
May 13, 2019
Messages
11
Hi. I want to ask one problem,
I have one column which is column "M".
If there are any blank cell in column "M", then it will replace with "MPTV".
So, it will loop start from row 2 until lastrow.
here is coding vba that I've try but cannot.

Code:
Sub REPLACEBLANK()
    'replace Blank to MPTV
    'in column M (SLoc column)
    Lastrow1 = Range("M" & Rows.Count).End(xlUp).Row
      Columns("M", Rows.Count).End(xlUp).Replace what:=Null, _
                            replacement:="MPTV", _
                            lookat:=xlPart, _
                            SearchOrder:=xlByRows, _
                            MatchCase:=False, _
                            SearchFormat:=False, _
                            ReplaceFormat:=False
End Sub


Please help me. thanks all
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Code:
Sub REPLACEBLANK()
'replace Blank to MPTV
'in column M (SLoc column)
On Error Resume Next
Range("M1:M" & Cells(Rows.Count, "M").End(xlUp).Row) _
    .SpecialCells(xlCellTypeBlanks) = "MPTV"
End Sub
 
Last edited:
Upvote 0
Code:
Sub REPLACEBLANK()
'replace Blank to MPTV
'in column M (SLoc column)
On Error Resume Next
Range("M1:M" & Cells(Rows.Count, "M").End(xlUp).Row) _
    .SpecialCells(xlCellTypeBlanks) = "MPTV"
End Sub

Thanks it works. Thanks a lot.
 
Upvote 0
Code:
Sub REPLACEBLANK()
'replace Blank to MPTV
'in column M (SLoc column)
On Error Resume Next
Range("M1:M" & Cells(Rows.Count, "M").End(xlUp).Row) _
    .SpecialCells(xlCellTypeBlanks) = "MPTV"
End Sub


I am sorry, I try to run with all the data, but its not work.
It only works if the all data are empty. If there are few data in column "M",
such as,

Column M |
123
123
123
113

213

313
133
-------------

It doesn't fill the blank with "MPTV". T_T
 
Upvote 0
Are the cells really blank?
Check with : =ISBLANK(M1) If blank it will return TRUE
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,884
Messages
6,122,082
Members
449,064
Latest member
MattDRT

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