Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default Can't get my code to work

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

--
Traa Dy Liooar

Jock
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Can't get my code to work

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

On Sep 7, 11:07*am, Jock wrote:
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

--
Traa Dy Liooar

Jock


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Can't get my code to work

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

--
Regards,

OssieMac


"Jock" wrote:

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

--
Traa Dy Liooar

Jock

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default Can't get my code to work

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


" wrote:

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

On Sep 7, 11:07 am, Jock wrote:
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

--
Traa Dy Liooar

Jock



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Verify Canadian Postal Code ~ make the code work jat Excel Programming 2 February 27th 09 09:12 PM
Why does this code not work? rk0909 Excel Discussion (Misc queries) 12 September 4th 08 10:42 PM
Code Does Not Work Minitman[_4_] Excel Programming 21 December 16th 04 09:30 PM
Help getting code to work. Frank Stone Excel Programming 1 July 28th 04 10:01 PM
Code won't work? Joe 90 Excel Programming 3 October 2nd 03 04:26 AM


All times are GMT +1. The time now is 11:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"