Change cell string if cell IsEmpty

I3atnumb3rs

New Member
Joined
Nov 2, 2018
Messages
34
Hello,

I'm trying to make it so that if colum B cell is empty to change column P cell to cancelled, but I can't seem to make it work. please help!

Sub ChngProgUnassigned()




Dim Col As Variant
Dim BlankRows As Long
Dim LastRow As Long
Dim r As Long
Dim StartRow As Long


Col = "B"
StartRow = 1
BlankRows = 1


LastRow = Cells(Rows.Count, Col).End(xlUp).Row




With ActiveSheet
For r = LastRow To StartRow + 1 Step -1
If IsEmpty(Cells(r, Col)) = True Then
.Cells(r, Col + 14).Value = "CANCELLED"
End If
Next r
End With


End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If the cells in col B are truly empty try
Code:
Sub AddCancel()
   Range("B:B").SpecialCells(xlBlanks).Offset(, 14).Value = "CANCELLED"
End Sub
 
Upvote 0
In that case use
Code:
Sub AddCancel()
   On Error Resume Next
   Range("B:B").SpecialCells(xlBlanks).Offset(, 14).Value = "CANCELLED"
   On Error GoTo 0
End Sub
 
Upvote 0
In that case use
Code:
Sub AddCancel()
   On Error Resume Next
   Range("B:B").SpecialCells(xlBlanks).Offset(, 14).Value = "CANCELLED"
   On Error GoTo 0
End Sub
You can still do this with a one-liner :lol:...
Code:
[table="width: 500"]
[tr]
	[td]Sub AddCancel()
  Range("B1", Cells(Rows.Count, "B").End(xlUp)).Replace "", "CANCELLED", xlWhole, , , , False, False
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
One slight problem with that, "CANCELLED" goes is col P not B ;)
 
Upvote 0
One slight problem with that, "CANCELLED" goes is col P not B ;)
Whoops! :oops:

A little messy, but it is still a one-liner...
Code:
[table="width: 500"]
[tr]
	[td]Range("B1", Cells(Rows.Count, "B").End(xlUp)).Offset(, 14) = Evaluate(Replace("IF(B1:B#="""",""CANCELLED"",IF(P1:P#="""","""",P1:P#))", "#", Cells(Rows.Count, "B").End(xlUp).Row))[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,218
Members
453,024
Latest member
Wingit77

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