Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Change Event duplicating action

I have a textbox that is getting a range address.
If the total of columns or row is higher than 5 I want to show an MsgBox and
clear its contents. It works fine but when the value becomes "" the change
event is obviously triggered but in this case since tha value is nothing it
still validates the number of columns/ros as higher than 5 and prompts the
message again

Private Sub TextBox1_Change()

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

I tried the afterupdate event but it doesn't work.

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Change Event duplicating action

Does this work:

Private Sub TextBox1_Change()
if TextBox1.Value = "" then exit sub

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

LuisE wrote:
I have a textbox that is getting a range address.
If the total of columns or row is higher than 5 I want to show an MsgBox and
clear its contents. It works fine but when the value becomes "" the change
event is obviously triggered but in this case since tha value is nothing it
still validates the number of columns/ros as higher than 5 and prompts the
message again

Private Sub TextBox1_Change()

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

I tried the afterupdate event but it doesn't work.

Thanks in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Change Event duplicating action

Darren, thanks for the prompt response
I found another approach that works turning the Application.EnableEvents =
False




Private Sub TextBox1_Change()
On Error GoTo XIT
Application.EnableEvents = False

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If

XIT:
Application.EnableEvents = True

End Sub

LuisE wrote:
I have a textbox that is getting a range address.
If the total of columns or row is higher than 5 I want to show an MsgBox and
clear its contents. It works fine but when the value becomes "" the change
event is obviously triggered but in this case since tha value is nothing it
still validates the number of columns/ros as higher than 5 and prompts the
message again

Private Sub TextBox1_Change()

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

I tried the afterupdate event but it doesn't work.

Thanks in advance.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Change Event duplicating action

After all it worked better than the other approach because I had references
to other objects. Thank you

"Darren Hill" wrote:

Does this work:

Private Sub TextBox1_Change()
if TextBox1.Value = "" then exit sub

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

LuisE wrote:
I have a textbox that is getting a range address.
If the total of columns or row is higher than 5 I want to show an MsgBox and
clear its contents. It works fine but when the value becomes "" the change
event is obviously triggered but in this case since tha value is nothing it
still validates the number of columns/ros as higher than 5 and prompts the
message again

Private Sub TextBox1_Change()

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

I tried the afterupdate event but it doesn't work.

Thanks in advance.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Change Event duplicating action

Glad to help :)

Darren

LuisE wrote:
After all it worked better than the other approach because I had references
to other objects. Thank you

"Darren Hill" wrote:

Does this work:

Private Sub TextBox1_Change()
if TextBox1.Value = "" then exit sub

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

LuisE wrote:
I have a textbox that is getting a range address.
If the total of columns or row is higher than 5 I want to show an MsgBox and
clear its contents. It works fine but when the value becomes "" the change
event is obviously triggered but in this case since tha value is nothing it
still validates the number of columns/ros as higher than 5 and prompts the
message again

Private Sub TextBox1_Change()

If Range(TextBox1.Value).Columns.Count 5 Or
Range(TextBox1.Value).Rows.Count 5 Then

MsgBox "Limit of 5 columns and rows"
TextBox1.Value = ""

Else
Call AnotherMacro

End If
End Sub

I tried the afterupdate event but it doesn't work.

Thanks in advance.

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
Action Event, CheckBox, Add Row and Textbox Ryan Excel Discussion (Misc queries) 2 July 17th 07 02:32 PM
Change to a Cell causes action Jordan Excel Programming 3 April 6th 06 05:15 PM
Change in action when converting to *.xla Udo Excel Programming 1 March 10th 06 10:26 AM
Cell change causes action [email protected] Excel Programming 5 March 8th 06 02:22 PM
MsgBox in Enter event causes combobox not to run Change event Richard Excel Programming 0 March 6th 06 02:52 PM


All times are GMT +1. The time now is 11:30 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"