VBA Enter Formula in blank cell if adjacent is non blank

Koza84

New Member
Joined
Mar 26, 2017
Messages
31
Hello.

I am looking for VBA solution to loop through column A and to enter formula =Today() in all blank cells in range A2:A1000 if adjacent cell in column B is not empty. For example in table below formula would need to be inserted in cells A3;A7, because they are blank and adjacent cells B3:B7 are not empty.

Best regards


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]24/11/18[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]24/11/18[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
If column B is values rather than formulae try
Code:
Sub FillBlanks()
   On Error Resume Next
   With Range("B2", Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlConstants)
      .Offset(, -1).SpecialCells(xlBlanks).Formula = "=today()"
   End With
   On Error GoTo 0
End Sub
 
Upvote 0
If column B is values rather than formulae try
Code:
Sub FillBlanks()
   On Error Resume Next
   With Range("B2", Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlConstants)
      .Offset(, -1).SpecialCells(xlBlanks).Formula = "=today()"
   End With
   On Error GoTo 0
End Sub

works brilliant ty
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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