Issue when updating blank cells automatically

miss c

New Member
Joined
Nov 19, 2018
Messages
4
Hi,


I am working on a scheduling calendar tool for my work. While a have a reasonable knowledge of Excel, I know absolutely nothing about VBA. I looked up codes examples for similar needs and have been “frankensteining” my way with some formulas but at this point, I need help. When I look at the code, I get the general idea but I am unable to come up with the specific structure.


I have a section where delivery dates are calculated automatically by formulas placed in hidden columns on the same sheet (same row, 104 columns away.) Since users can input different dates to adjust the time frame when needed, errors can be introduced if a user is deleting the reference to the cell that contains the original formula. I was thinking to avoid this issue by creating a macro that will return the original cell reference (containing the formula) whenever a user is deleting any cell in the range concerned. (Ex: deleting content of cell H6 would return “=DH6”)


This is what I have so far. I did a test with simple formulas and it was working but when I integrate the code in the actual calendar, Excel is crashing. And just before it closes, I get the message “Run-time error '-2147417848 (80010108)': Method 'Value' of object 'Range' failed” I assume the segment for the automatic update is somehow incompatible with the code to replace blank cells?


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H6:AH9")) Is Nothing Then
    Call UpdateBlank
    End If
    
End Sub




Sub UpdateBlank()
    
    For Each c In Range("H6:AH9")
        If c.Value = "" Then c.Value = "=RC[104]"
    Next
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi there. I think this version of your UpdateBlank subroutine should work:
Code:
Sub UpdateBlank()
    Application.EnableEvents = False
    For Each c In Range("H6:AH9")
        If c.Value = "" Then c.Formula = "=RC[104]"
    Next
    Application.EnableEvents = True
End Sub
 
Upvote 0
It works, this is exactly what I needed. I should have asked way sooner and saved myself the trouble... Thank you!
 
Upvote 0

Forum statistics

Threads
1,222,749
Messages
6,167,958
Members
452,158
Latest member
MattyM

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