Insert formula if blank cell

mjtolent

New Member
Joined
Oct 1, 2020
Messages
14
Office Version
  1. 2013
Platform
  1. Windows
Hi All,

Trying to right some code that will do the following:

  1. Check a selected column range for blank cells
  2. If any cell is blank insert a formula that uses figures in the 2 adjacent columns on the same row.
  3. Move to next blank cells until complete.
I've tried a couple of things, but getting nowhere, thanks in advance
mj
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Assuming you are in Sheet1 using Column A.

VBA Code:
Sub test()
Dim cl As Object, lastRow As Long
With Sheets("Sheet1")
    lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For Each cl In .Range("A1:A" & lastRow)
        If cl.Value = "" Then cl.Value = cl.Offset(0, 1).Value & " " & cl.Offset(0, 2).Value
    Next cl
End With
End Sub
 
Upvote 0
What column do you want to check & what is the formula?
 
Upvote 0
Fluff,
Example, I want to check a selection of cells in column E and if blank divide column F by G from same row
 
Upvote 0
Do you want the code to run on all of col E or just cells that you have selected?
If cells you have select, will it always be a contiguous range of cells?
 
Upvote 0
The data in column E will be of varying lengths dependent on certain criteria. I've used vba to make the selection, but need it to check the selected range for blanks and insert the formula to each blank cell in the selection only
 
Upvote 0
Assuming you are in Sheet1 using Column A.

VBA Code:
Sub test()
Dim cl As Object, lastRow As Long
With Sheets("Sheet1")
    lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For Each cl In .Range("A1:A" & lastRow)
        If cl.Value = "" Then cl.Value = cl.Offset(0, 1).Value & " " & cl.Offset(0, 2).Value
    Next cl
End With
End Sub
Thanks for taking the time to offer a solution. Will test and let you know if successful
 
Upvote 0
Ok, how about
Rich (BB code):
Sub mjtolent()
   With Range("E2:E" & Range("G" & Rows.Count).End(xlUp).Row)
      .SpecialCells(xlBlanks).FormulaR1C1 = "=rc[1]/rc[2]"
      .Value = .Value
   End With
End Sub
This will work for all blanks in col E, remove the line in blue if you want to keep the formula.
 
Upvote 0

Forum statistics

Threads
1,215,833
Messages
6,127,156
Members
449,366
Latest member
reidel

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