Change cell string if cell IsEmpty

I3atnumb3rs

New Member
Joined
Nov 2, 2018
Messages
32
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
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,303
Office Version
  1. 365
Platform
  1. Windows
If the cells in col B are truly empty try
Code:
Sub AddCancel()
   Range("B:B").SpecialCells(xlBlanks).Offset(, 14).Value = "CANCELLED"
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,303
Office Version
  1. 365
Platform
  1. Windows
You're welcome
 

I3atnumb3rs

New Member
Joined
Nov 2, 2018
Messages
32

ADVERTISEMENT

So little snag, when there's no string "CANCELLED" the code seems to break :(
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,303
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,308
Office Version
  1. 2010
Platform
  1. Windows
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,303
Office Version
  1. 365
Platform
  1. Windows
One slight problem with that, "CANCELLED" goes is col P not B ;)
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,308
Office Version
  1. 2010
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,108,974
Messages
5,525,990
Members
409,673
Latest member
Riseee

This Week's Hot Topics

Top