VBA Excel - Releasing variables from memory - getting error - can't see why

Sparkle99

Board Regular
Joined
May 22, 2009
Messages
119
Hi,
I'm trying to release some variables at the end of a loop

The line...
Set CurrentRow = Nothing
causes...
Compile Error - Object Required

Excel 2010. I have tried CurrentRow defined as Long, String and others.
I have tried the DIM statement outside of the loop or inside - makes not difference
This is happening for ALL of my 'Set xxx = Nothing' statements - not specific to this variable.

Any suggestions ?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Use Like This if string

Code:
 CurrentRow = VbNullString

If Long or interger or double type

Code:
 CurrentRow = Empty
 
Upvote 0
Hmmm, this may get me a battering but I'm not even remotely convinced there is an actual need to release memory in this way as a generic rule.

The garbage collector will release the memory as soon as the variable goes out of scope. Sure, there are situations where it is necessary to do this explicitly for example to prevent circular references between classes but in the main I rarely ever release memory explicitly.

Still it is considered best practice and there's certainly no harm in doing it, maybe I'm just lazy.... ;)

I'd be very interested in any article which shows that it is absolutely required (other than the dodgy DAO access thing).
 
Last edited:
Upvote 0
Thanks Andrew, I'd seen that before and the linked thread (on DDoE) makes for interesting reading. It seems really to come down to personal preference unless there's a genuine need for it - of which of course there can be which I eluded to in my earlier post.

Still, no harm in including it anyway :)
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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