Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Click event not working

I have an input userform that has OK, Cancel and Clear buttons. when
you input something and click OK, it writes it to a spreadsheet. If
you click Cancel it closes the form an does not input anything. If you
click clear, it clears all the values in the form. it clears it by
clearing the contents of the spreadsheet then reactivating the form
which reads the input from the cells. I tried to write a sub so that
when you clear the input and then click cancel, the input will return
to what it was before clicking on clear (when the form is opened
again). here ar ethe subs for Cancel and Clear:

Private Sub CommandButtonCLear_Click()
Sheets("sheet1").Range("D34:H39").Value =
Sheets("sheet1").Range("B8:F13").Value
Sheets("sheet1").Range("B8:F13").ClearContents

Unload UserFormMultiLC
UserFormMultiLC.Show
Sheets("sheet1").Range("D33").Value = 1
End Sub
----------------------------------------------------------------------------------------------------------------------------------------
Private Sub CommandButtonMultiLCCancel_Click()
If Sheets("sheet1").Range("D33").Value = 1 Then
Sheets("sheet1").Range("B8:F13").Value =
Sheets("sheet1").Range("D34:H39").Value
Else
End If

UserFormMultiLC.Hide
End Sub


the clear sub is working fine. it writes the input range to a new
range before clearing the input range and restarting the userform. but
when I click the cancel button, it is not writing the saved input
range. into the original input range. I cannot understand why. does
this make sense? is there a better way to go about this? thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Click event not working

Jacob -
from what i can see (being a non-guru), it looks to me
like your 2nd range simply EQUALS what the first range
consists of. then when you clear the initial range, you
are inadvertently clearing the 2nd range, too.

to try to illustrate:
YourSub clear()
cell b3 = "5"
cell x3 = "=b3"
when you clear b3, x3 also clears.
(if i'm understanding your code correctly).

why don't you try (in simplified language):
YourSub clear()
cell b3 = "5"
copy b3 to x3
clear b3

now your old values are still contained in x3, for
re-installing when they choose
YourSub cancel().

susan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Click event not working

Private Sub CommandButtonMultiLCCancel_Click()
With Sheets("sheet1")
If .Range("D33").Value = 1 Then
.Range("D34:H39").Copy .Range("B8:F13")
End If
End With
End If


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Jacob" wrote in message
ups.com...
I have an input userform that has OK, Cancel and Clear buttons. when
you input something and click OK, it writes it to a spreadsheet. If
you click Cancel it closes the form an does not input anything. If you
click clear, it clears all the values in the form. it clears it by
clearing the contents of the spreadsheet then reactivating the form
which reads the input from the cells. I tried to write a sub so that
when you clear the input and then click cancel, the input will return
to what it was before clicking on clear (when the form is opened
again). here ar ethe subs for Cancel and Clear:

Private Sub CommandButtonCLear_Click()
Sheets("sheet1").Range("D34:H39").Value =
Sheets("sheet1").Range("B8:F13").Value
Sheets("sheet1").Range("B8:F13").ClearContents

Unload UserFormMultiLC
UserFormMultiLC.Show
Sheets("sheet1").Range("D33").Value = 1
End Sub
--------------------------------------------------------------------------

--------------------------------------------------------------
Private Sub CommandButtonMultiLCCancel_Click()
If Sheets("sheet1").Range("D33").Value = 1 Then
Sheets("sheet1").Range("B8:F13").Value =
Sheets("sheet1").Range("D34:H39").Value
Else
End If

UserFormMultiLC.Hide
End Sub


the clear sub is working fine. it writes the input range to a new
range before clearing the input range and restarting the userform. but
when I click the cancel button, it is not writing the saved input
range. into the original input range. I cannot understand why. does
this make sense? is there a better way to go about this? thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Click event not working

I understand what you are describing, but I have checked that. when I
click the clear button, everything does what I want it to do. range1
is cleared and range2 is updated with whatever range1 was before it was
cleared. and cell D33 is changed to 1 which indicated the cells have
been cleared.

when I click the cancel button, according to my code, if cell D33 is 1
(which it will be if the cells have been cleared) it will only copy
range2 to range1 and that's it. there is no clearing involved in the
cancel sub. instead, the cells are not being copied to range1 and
range2 does not change. so I know they are not being cleared, or
overwritten with zero values.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Click event not working

ok, so it's the blind leading the blind..........
maybe bob's idea will work.
:)
susan



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Click event not working

bob,
that does the exact same thing that my code does. I tried it. I
cannot figure out why Range("B8:F13") will not copy to Range("B8:F13").
it makes no sense. it works fine the other way around. thanks for
your help.


On Oct 19, 11:41 am, "Bob Phillips" wrote:
Private Sub CommandButtonMultiLCCancel_Click()
With Sheets("sheet1")
If .Range("D33").Value = 1 Then
.Range("B8:F13").Copy .Range("B8:F13")
End If
End With
End If

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Jacob" wrote in oglegroups.com...

I have an input userform that has OK, Cancel and Clear buttons. when
you input something and click OK, it writes it to a spreadsheet. If
you click Cancel it closes the form an does not input anything. If you
click clear, it clears all the values in the form. it clears it by
clearing the contents of the spreadsheet then reactivating the form
which reads the input from the cells. I tried to write a sub so that
when you clear the input and then click cancel, the input will return
to what it was before clicking on clear (when the form is opened
again). here ar ethe subs for Cancel and Clear:


Private Sub CommandButtonCLear_Click()
Sheets("sheet1").Range("D34:H39").Value =
Sheets("sheet1").Range("B8:F13").Value
Sheets("sheet1").Range("B8:F13").ClearContents


Unload UserFormMultiLC
UserFormMultiLC.Show
Sheets("sheet1").Range("D33").Value = 1
End Sub
----------------------------------------------------------------------------------------------------------------------------------------


Private Sub CommandButtonMultiLCCancel_Click()
If Sheets("sheet1").Range("D33").Value = 1 Then
Sheets("sheet1").Range("B8:F13").Value =
Sheets("sheet1").Range("D34:H39").Value
Else
End If


UserFormMultiLC.Hide
End Sub


the clear sub is working fine. it writes the input range to a new
range before clearing the input range and restarting the userform. but
when I click the cancel button, it is not writing the saved input
range. into the original input range. I cannot understand why. does
this make sense? is there a better way to go about this? thanks.


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
userform label double-click goes to click event John Paul Fullerton Excel Programming 3 May 19th 06 05:54 PM
Select Multi in Listbox - Event Click not working François Excel Programming 0 March 30th 06 07:56 PM
Click event to run only once gavmer[_85_] Excel Programming 0 October 5th 04 12:18 AM
Click event to run only once gavmer[_83_] Excel Programming 0 October 1st 04 01:24 AM
Click Event Nichevo Excel Programming 2 December 4th 03 04:31 AM


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