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


AB
24/11/18A
24/11/18B
B
B
B
B
B

<tbody>
</tbody>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

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