Can't get my code to work

J

Jock

Hi all,
Could somebody look at the following code and, essentially, make it work
please?
Private Sub CommandButton2_Click()
Dim Target As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target.Me.Range("L4:L10000")) Is Nothing Then
With Target
If .Value = "P" Then
.Offset(0, 1).Value = TextBox1.Text 'copies text box data to cell
End If
End With
'Cancel = True
End If

TIA
 
P

paul.robinson

Hi
Replace
Intersect(Target.Me.Range("L4:L10000"))

with
Intersect(Target, Me.Range("L4:L10000"))

What does "Me" refer to here? Try leaving it out

Intersect(Target, Range("L4:L10000"))

regards
Paul
 
O

OssieMac

Hello Jock,

I am not sure that what I have answered is what you want. I have assumed
that CommandButton2 is on a worksheet because you have used Me with the range
and would have to be a worksheet. Your code does not show what range Target
represents. I have set it to Activecell just for the test.

You had a dot between Target and Me and should be a comma.


Private Sub CommandButton2_Click()
Dim Target As Range

Set Target = ActiveCell

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("L4:L10000")) Is Nothing Then
With Target
If .Value = "P" Then
.Offset(0, 1).Value = TextBox1.Text 'copies text box data to cell
End If
End With
'Cancel = True
End If

ws_exit:
End Sub
 
J

Jock

Got it.
Apologies for being vague, but used Ossies code and Paul's "lose the .me"
advice and it works now.
It is on a User Form btw
--
Traa Dy Liooar

Jock


Hi
Replace
Intersect(Target.Me.Range("L4:L10000"))

with
Intersect(Target, Me.Range("L4:L10000"))

What does "Me" refer to here? Try leaving it out

Intersect(Target, Range("L4:L10000"))

regards
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top