Code Works, then Stops Working

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I'm at a loss as to why, but when I run this code the first time, it runs as expected. When I try to run it again, it fails at the line in red. Yes, there is more code underneath the red line, but I'm only posting up to the failure point.
Rich (BB code):
Private Sub cmd_Submit_Click()

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Dim m As Workbook
Dim mT, mN, mV, mI As Worksheet
Dim mILR, mINR As Long

Set m = ThisWorkbook
Set mT = m.Sheets("Template")
Set mV = m.Sheets("Variables")
Set mI = m.Sheets("Inventory")

mINR = Sheets("Inventory").Range("D" & Rows.Count).End(xlUp).Offset(1).Row
 
Last edited by a moderator:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
What is the error?

If the code runs the first time, but does not run the second time and you don't show the code, it would be hard to formulate an answer.

Your variables should be dim'd seperately.
Code:
Dim mT, mN, mV, mI As Worksheet

Should be
Code:
Dim mTAs Worksheet, mNAs Worksheet, mVAs Worksheet, mI As Worksheet
Same goes for the Long variables.
 
Upvote 0
Does it make any difference if you change that line to this:

Rich (BB code):
mINR = mI.Range("D" & Rows.Count).End(xlUp).Offset(1).Row
 
Upvote 0
Solution

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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