"VBA Error - "invalid use of Me Keyword"

Johnny C

Well-known Member
Joined
Nov 7, 2006
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
I've got a userform which monitors progress of some VBA.

In a sub called by the userform.activate event, there are a load of Me.<> statements which update things on the userform.

it was working fine but I've made a lot of changes - nothing to do with the userform, just processing changes, and haven't run the macro for a few weeks.

Now I've jsut started it for final testing, and it falls over on compile with the following error:

"Invalid use of Me Keyword"
The line it's falling over on (which was fine before) is
Code:
    Me.lblCurrentStatus.Caption = "Initialising - clearing old data"

The error help isn't much use, it's just about using Me in class modules, not ordinary modules, and as I say it was working fine before.

Can anyone shed light on this?

TIA
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Is the code in the form module?
 
Upvote 0
No, it's called from the modules. I take it I would need to move them back into the form module?
 
Upvote 0
No, it's called from the modules. I take it I would need to move them back into the form module?
Or qualify it fully:-
Code:
[COLOR=red]Forms![[I]formname[/I]][/COLOR].lblCurrentStatus.Caption = "Initialising - clearing old data"
 
Upvote 0
They don't pay me enough to type things out in full when Me will do ;)

It's a curious case where Berty Russell's modified Occam's razor
Whenever possible, substitute constructions out of known entities for inferences to unknown entities
conflicts with the actual Billy Occam version;
entia non sunt multiplicanda praeter necessitatem
I really shouldn't be lazy though, and go with the Berty version via Find&Replace when it's all tested.
 
Upvote 0
Hello. I'm getting the error referenced in the thread title in a worksheet that worked previously.

I'm using this code to try to get a user to put data in a cell before moving on:

Private Sub Worksheet_Deactivate()
Dim rngCheck As Range
Dim cel As Range
Dim j As String
Dim i As Integer








Set rngCheck = Me.Range("B8:B11")






i = 0
For Each cel In rngCheck
If IsEmpty(cel) Then
i = i + 1
j = j & cel.Address & vbNewLine
End If
Next cel


If i = 0 Then Exit Sub




Me.Activate
MsgBox "Sorry, you must enter a value in: " & vbNewLine & j
End Sub



Any ideas? Thank you.
 
Upvote 0
Since this is the deactivate event, I'd say you don't need the me. In me. Range and me.Activate is unnecessary as you haven't activated anything else before the worksheet is deactivated
 
Upvote 0
Thank you for the quick reply. Please forgive my ignorance but what would I change to fix that?
 
Upvote 0
Your code works ok for me, which Me is highlighted when you get the error?
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,386
Members
449,221
Latest member
DFCarter

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