Way for Excel to Double Check before Running Module? VBA

theteerex

Board Regular
Joined
Mar 2, 2018
Messages
102
I have a macro that adds records to a table if another table has a new row added.
It works fine and doesn't produce errors.
There are times however when it adds records when no new row was added to the feeder table.

Is there something in the code that makes it run anyway?

Code:
Private Sub Worksheet_Calculate()


    Dim n As Long
    n = GetTableSize() [B][COLOR=#008000]'GetTableSize monitors a static cell which calculates table number of used rows in a table. If that number is different than LastRowNumber...[/COLOR][/B]
    If n > LastRowNumber Then NewDatabaseEntry [COLOR=#008000][B]' NewDatabaseEntry adds new records[/B][/COLOR]
[COLOR=#008000][B]    ' Always set LastRowNumber so that even after entries are deleted (n < NumRows),[/B][/COLOR]
[COLOR=#008000][B]    ' adding new entries will work correctly.[/B][/COLOR]
    LastRowNumber = n [B][COLOR=#008000]'It then resets the values so they are equal again[/COLOR][/B]


End Sub

Sometimes, I'm working in the feeder table, and then I go check the records table and a new set of records has been added, even though no new rows were added.
Is there a way to add a message box that asks if you meant to add a new record and if you click no, it stops this from running?
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I am trying to get this code to work correctly.
Code:
Private Sub Worksheet_Calculate()


    Dim n As Long


    
    rspn = MsgBox("Did you want to add a project?", vbYesNo)
    n = GetTableSize()
    
    If n > LastRowNumber Then Call rspn
        If rspn = vbNo Then
            MsgBox ("No Project Added")
        Exit Sub
        If rspn = vbYes Then NewDatabaseEntry
        LastRowNumber = n
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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