Clearing Blank Cells, or the appearance of Blank Cells.

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I am trying to insert text (Column E) in a cell if there is a number in another cell Column E. The problem is even for the blank cells "TBD" is being inserted in Column D. Now I'm trying to clear the contents of Column D, so excel doesn't think there is data there. I would need to except for this code to ignore one is the word "ROLL CALL" and another is any four digit number "####". Column D is in a Text format.

VBA Code:
Sub DoNotContainrollcall()

Dim rng As Range
Dim cell As Range
Dim ContainWord As String

With Sheets("72 HR")
      With .Range("D2", .Range("D" & Rows.Count).End(xlUp))

  ContainWord = "ROLL CALL". "####"

  For Each cell In rng.Cells
    If cell.Find(ContainWord) Is Nothing Then cell.Clear
  Next cell
End With
End With
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How about
VBA Code:
Sub MM1()
Dim cell As Range
  For Each cell In Sheets("72 HR").Range("D2", Range("D" & Rows.Count).End(xlUp))
    If cell.Value = "ROLL CALL" Or IsNumeric(cell) And Len(cell) = 4 Then
        cell.Clear
    End If
  Next cell
End Sub
 
Upvote 0
Thank you I think we are heading in the right directions. As you see in the second screen shot to the right in cleared everything out of Column D. I need Roll Call and the four digit number to remain. When this is done, I have another macro when activated will place a TBD in Column E on the same row as the time is in Column D. For some reason the blank appearing spaces in Column D, Excel thinks there is data in there. If there is a blank space in Column D then in Column E on the same row will also be blank. Thank you,



Delete Roll Call and number.JPG
 
Upvote 0
So ....
VBA Code:
Sub MM1()
Dim cell As Range
  For Each cell In Sheets("72 HR").Range("D2", Range("D" & Rows.Count).End(xlUp))
    If cell.Value <> "ROLL CALL" And Len(cell) <> 4 Then
        cell.Clear
    End If
  Next cell
End Sub
 
Upvote 0
Solution
Thank you, that is beautiful. Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

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