Link to home
Start Free TrialLog in
Avatar of hermesalpha
hermesalphaFlag for Paraguay

asked on

What happens with values in a VBA code in Excel 2007 when I insert new rows on the worksheet?

I received below code earlier from an EE member here, and now I want to add new rows on this worksheet, but first need to know if that is accounted for automatically in the VBA code? Or would I need to change the VBA to reflect the number of new rows I insert?

The code makes sure that if I first enter a value in the cells referenced to in that code and then delete this value, then the original formula gets restored in the cell.

This is the VBA code:
Option Explicit
Dim KeepValue(1 To 8) As Variant

Private Sub Worksheet_Calculate()
    Dim i As Integer
    On Error GoTo ErrorOut
    Application.EnableEvents = False
    For i = 1 To 8
        If KeepValue(i) <> Cells(34, i + 15) And Cells(35, i + 15).HasFormula = True Then
            Cells(35, i + 15) = Cells(34, i + 15)
        End If
        KeepValue(i) = Cells(34, i + 15)
    Next i
ErrorOut:
    Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("Q35:X35")) Is Nothing And Target.Count = 1 Then
        On Error GoTo ErrorOut
        Application.EnableEvents = False
            If IsEmpty(Target) Then
                Target.FormulaR1C1 = "=IFERROR(R[-1]C,"""")"
            End If
ErrorOut:
        Application.EnableEvents = True
    End If
End Sub

Open in new window

SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've requested that this question be closed as follows:

Accepted answer: 125 points for Excel_Expert's comment #a41385404
Assisted answer: 125 points for ssaqibh's comment #a41384916
Assisted answer: 125 points for Qlemo's comment #a41384913
Assisted answer: 125 points for hgholt's comment #a41385422

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Avatar of hermesalpha

ASKER

I suggest to award 150 points to comment 04 and 22 because they included VBA also, and 100 points to comment 16 and 13.
I suggest to award 150 points to comment 04 and 22 because they included VBA also, and 100 points to comment 16 and 13.