Help with VBA code if cell is blank in column C put in formula, then convert to value

willow1985

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

I am looking to clean up some data in another Macro I have and am trying to figure out the code for one part of the clean up.
Basically in column C there are ship dates and in column B there are due dates. When there is a blank cell in column C I want it to bring over the value from column B.

The below code I have is giving me an error so I am missing something...

VBA Code:
Dim rCell As Range

For Each rCell In Range("C2:C")

    If rCell.Value = "" Then

        rCell.Formula = "=[@[Due Date]]"
        rCell.Value = rCell.Value
        
    End If
    
Next rCell

Any help would be appreciated.

Thank you! :)
 
How about
VBA Code:
With ActiveSheet.ListObjects("SR").ListColumns("Ship Date").DataBodyRange
   .Value = Evaluate(Replace("if(@<>"""",@," & .Offset(, -1).Address & ")", "@", .Address))
End With
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I went with something more simple as it is quicker. Although the above code works it is very very slow.
I added a column in the table (AV) that has the formula: =IF([@[Ship Date]]="",[@[Due Date]],[@[Ship Date]])
When new data is put in it will give me the Due Date for only blank cells in the Ship Date column. Then the below VBA code will just copy that column data over.
This extra column will remain hidden. Not the fanciest of solutions but it is a lot quicker than the above.

Thank you all for your help. It is much appreciated!

VBA Code:
Columns("AU:AW").Select

Selection.EntireColumn.Hidden = False

Range("AV2").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Range("C2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Application.CutCopyMode = False

Columns("AV:AV").Select

Selection.EntireColumn.Hidden = True

Range("A2").Select
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,816
Members
449,095
Latest member
m_smith_solihull

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