Compile Error: Variable Not Defined

BrittKnee

Board Regular
Joined
Dec 4, 2017
Messages
82
Hey there! I am trying to get some code to work and had a friend help me try to clean it up. It worked when he ran through it, but now I am getting a Compile Error. I have made the line where the error occurs bold. The string of code is as follows:
I would also like to add that I renamed Sheet4 (CharityCare).

Dim lastRow As Long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'Categorize as Insured or Uninsured (Charity)

lastRow = Range(Range("A10"), Range("A10").End(xlDown)).Count + 9

With ws_CharityCare
.Activate

.Range("B10:B" & lastRow).Formula = "=IF(RC[7]>1,""Insured"",""Uninsured"")"

'Create Fiscal Year Based Off of Discharge Date (Charity)
.Range("K10:K" & lastRow).Formula = "=YEAR(RC[-7])+(MONTH(RC[-7])>='FY Calculation'!R[-8]C[-10])"

Thanks!
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try:
Code:
With Sheets("CharityCare")
 
Upvote 0
if you renamed the Sheet4 tab name to CharityCare it is

Code:
With Sheets("CharityCare")

If you renamed the Sheet4 codename to CharityCare it is

Code:
With CharityCare

and in either case you don't need the .Activate line.

Plus the lastRow variable should probably be within the With statement.


Code:
lastRow = .Range(.Range("A10"), .Range("A10").End(xlDown)).Count + 9
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,030
Members
448,940
Latest member
mdusw

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