Help with VBA code, checking if cells are blank

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
886
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need help with a section of the below code. Basically the area I am having trouble with is checking if column A (Date In) has any blanks and if so proceed with the below code to replace the blanks with a formula. If there are no blanks then skip to the formatting section.

Any help sorting this out would be greatly appreciated!

VBA Code:
Sheets("Flow of Repair").Select

If IsEmpty Range("FoR[Date In]") = True Then

    x = Range("A" & Rows.Count).End(xlUp).Row
     
    If x > 1 Then
        With Range("A2:A" & x).SpecialCells(xlCellTypeBlanks)
            .FormulaR1C1 = "=[@[Date Out]]"
        End With
    End If
    
Else

Range("FoR[Station Time (Days)]").Select
With Selection
    .NumberFormat = "0"
    .Value = .Value
End With


Range("S1").Select

End If
Application.ScreenUpdating = True

'
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
How about
VBA Code:
   With ActiveSheet.ListObjects("FoR")
      On Error Resume Next
      .ListColumns("Date In").DataBodyRange.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=[@[Date Out]]"
      On Error GoTo 0
      With .ListColumns("Station Time (Days)").DataBodyRange
         .NumberFormat = "0"
         .Value = .Value
      End With
   End With
 
Upvote 0
Solution
How about
VBA Code:
   With ActiveSheet.ListObjects("FoR")
      On Error Resume Next
      .ListColumns("Date In").DataBodyRange.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=[@[Date Out]]"
      On Error GoTo 0
      With .ListColumns("Station Time (Days)").DataBodyRange
         .NumberFormat = "0"
         .Value = .Value
      End With
   End With
If I wanted to remove the formatting portion and put another code there, how would I go about doing that? do I just remove the below section entirely and add the new code to the bottom?

VBA Code:
'Remove this:

With .ListColumns("Station Time (Days)").DataBodyRange
         .NumberFormat = "0"
         .Value = .Value
      End With
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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