Insert 0000 based on 2 criteria in a particular Column

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I got the VBA below with the help of "Fluff" from this website. Before I add "0000" to Column D I need to ensure the corresponding cell in Column C is NOT blank OR contains "N/A". Thank you.


VBA Code:
Sub Insert_Null()
   With Sheets("72 HR")
   Columns("D:D").NumberFormat = "@"
     .Range("D2:D" & .Range("C" & Rows.Count).End(xlUp).Row).SpecialCells(xlBlanks).Value = "0000"
   End With
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This might give you the result you're after - I added a loop to evaluate the values in column C:

VBA Code:
Sub Insert_Null()
    With Sheets("72 HR")
    
        Dim r As Long 'row number for the loop
                 
        Columns("D:D").NumberFormat = "@"
        
        For r = 2 To .Range("C" & Rows.Count).End(xlUp).Row
        
            If (.Cells(r, 3) = "" Or .Cells(r, 3) = "N/A") And IsEmpty(.Cells(r, 4)) Then
                  .Cells(r, 4).Value = "0000"
            End If
            
        Next r
    
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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