Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Listbox Code

I have a cell containing a validation listbox. I want to write a code such
that if the user select "No Change", Cell A1 and B2 becomes blank. Below is
my code which is not working:

Private Sub Workbook_Change()
If .Range("C1")= "No Change" Then
.Range("A1") = " "
.Range("B2") = " "
End If
End Sub

Thanks for your help in advance.

--
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox Code

This is untested:

Private Sub Worksheet_Change()
If Range("C1")= "No Change" Then
Range("A1") = ""
Range("B2") = ""
End If
End Sub

The dots are normally used in conjunction with a "With" statement and to get
a null value in the cell, omit the space between the quote marks. Also the
code will work better in a Worksheet code module as opposed to the
ThisWorkbook module.



"Daviv" wrote:

I have a cell containing a validation listbox. I want to write a code such
that if the user select "No Change", Cell A1 and B2 becomes blank. Below is
my code which is not working:

Private Sub Workbook_Change()
If .Range("C1")= "No Change" Then
.Range("A1") = " "
.Range("B2") = " "
End If
End Sub

Thanks for your help in advance.

--
Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Listbox Code

JLGWhiz,

I tried what you recommend. It does not worked. Anything additional help
welcome.
--
Thanks!


"JLGWhiz" wrote:

This is untested:

Private Sub Worksheet_Change()
If Range("C1")= "No Change" Then
Range("A1") = ""
Range("B2") = ""
End If
End Sub

The dots are normally used in conjunction with a "With" statement and to get
a null value in the cell, omit the space between the quote marks. Also the
code will work better in a Worksheet code module as opposed to the
ThisWorkbook module.



"Daviv" wrote:

I have a cell containing a validation listbox. I want to write a code such
that if the user select "No Change", Cell A1 and B2 becomes blank. Below is
my code which is not working:

Private Sub Workbook_Change()
If .Range("C1")= "No Change" Then
.Range("A1") = " "
.Range("B2") = " "
End If
End Sub

Thanks for your help in advance.

--
Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Listbox Code

JLG,

It did not worked. Anymore help welcome.

--
Thanks!


"JLGWhiz" wrote:

This is untested:

Private Sub Worksheet_Change()
If Range("C1")= "No Change" Then
Range("A1") = ""
Range("B2") = ""
End If
End Sub

The dots are normally used in conjunction with a "With" statement and to get
a null value in the cell, omit the space between the quote marks. Also the
code will work better in a Worksheet code module as opposed to the
ThisWorkbook module.



"Daviv" wrote:

I have a cell containing a validation listbox. I want to write a code such
that if the user select "No Change", Cell A1 and B2 becomes blank. Below is
my code which is not working:

Private Sub Workbook_Change()
If .Range("C1")= "No Change" Then
.Range("A1") = " "
.Range("B2") = " "
End If
End Sub

Thanks for your help in advance.

--
Thanks!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Listbox Code

To put under Worksheet Change Event

If target.column=3 and target.row=1 then
if target.value="No Change" then
target.offset(1,-1) = ""
target.offset(,-2)=""
end If
end if




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Listbox Code

Are you getting an error?

If not, then you probably have events disabled. Put this code in a general
module (insert = Module in the vbe)

Sub turnOnEvents()
application.EnableEvents = True
End sub

Now run it with Tools=Macro=Macros, select TurnOnEvents and click Run.

then right click on the sheet tab, select view code, and put in code like this

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$1" then
if Instr(1,application.Trim(Target),"no change", _
vbTextCompare) then
me.Range("A1,B2").Clearcontents
end if
end if
End sub

--
Regards,
Tom Ogilvy

"Daviv" wrote:

JLGWhiz,

I tried what you recommend. It does not worked. Anything additional help
welcome.
--
Thanks!


"JLGWhiz" wrote:

This is untested:

Private Sub Worksheet_Change()
If Range("C1")= "No Change" Then
Range("A1") = ""
Range("B2") = ""
End If
End Sub

The dots are normally used in conjunction with a "With" statement and to get
a null value in the cell, omit the space between the quote marks. Also the
code will work better in a Worksheet code module as opposed to the
ThisWorkbook module.



"Daviv" wrote:

I have a cell containing a validation listbox. I want to write a code such
that if the user select "No Change", Cell A1 and B2 becomes blank. Below is
my code which is not working:

Private Sub Workbook_Change()
If .Range("C1")= "No Change" Then
.Range("A1") = " "
.Range("B2") = " "
End If
End Sub

Thanks for your help in advance.

--
Thanks!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Listbox Code

Kemal, Your codes works Thanks. And Thanks everybody for your input.
--
Thanks!


" wrote:

To put under Worksheet Change Event

If target.column=3 and target.row=1 then
if target.value="No Change" then
target.offset(1,-1) = ""
target.offset(,-2)=""
end If
end if



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox Code

Daviv, Is the text "No Change" a message in the validation box or is it a
text value in the cell?

"Daviv" wrote:

JLG,

It did not worked. Anymore help welcome.

--
Thanks!


"JLGWhiz" wrote:

This is untested:

Private Sub Worksheet_Change()
If Range("C1")= "No Change" Then
Range("A1") = ""
Range("B2") = ""
End If
End Sub

The dots are normally used in conjunction with a "With" statement and to get
a null value in the cell, omit the space between the quote marks. Also the
code will work better in a Worksheet code module as opposed to the
ThisWorkbook module.



"Daviv" wrote:

I have a cell containing a validation listbox. I want to write a code such
that if the user select "No Change", Cell A1 and B2 becomes blank. Below is
my code which is not working:

Private Sub Workbook_Change()
If .Range("C1")= "No Change" Then
.Range("A1") = " "
.Range("B2") = " "
End If
End Sub

Thanks for your help in advance.

--
Thanks!

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Listbox Code

No Change is 1 of the values in the listbox generated from a validation.
--
Thanks!


"JLGWhiz" wrote:

Daviv, Is the text "No Change" a message in the validation box or is it a
text value in the cell?

"Daviv" wrote:

JLG,

It did not worked. Anymore help welcome.

--
Thanks!


"JLGWhiz" wrote:

This is untested:

Private Sub Worksheet_Change()
If Range("C1")= "No Change" Then
Range("A1") = ""
Range("B2") = ""
End If
End Sub

The dots are normally used in conjunction with a "With" statement and to get
a null value in the cell, omit the space between the quote marks. Also the
code will work better in a Worksheet code module as opposed to the
ThisWorkbook module.



"Daviv" wrote:

I have a cell containing a validation listbox. I want to write a code such
that if the user select "No Change", Cell A1 and B2 becomes blank. Below is
my code which is not working:

Private Sub Workbook_Change()
If .Range("C1")= "No Change" Then
.Range("A1") = " "
.Range("B2") = " "
End If
End Sub

Thanks for your help in advance.

--
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
listbox code Jennifer Excel Programming 6 March 5th 07 03:14 PM
MORE listbox code Jennifer Excel Programming 5 May 26th 06 03:46 AM
Modification of listbox to listbox code Sam S via OfficeKB.com Excel Programming 0 July 28th 05 12:02 PM
Modification of listbox to listbox code R.VENKATARAMAN Excel Programming 0 July 28th 05 05:36 AM
Listbox Propery code Mike Fogleman Excel Programming 3 January 1st 04 04:27 PM


All times are GMT +1. The time now is 10:58 PM.

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

About Us

"It's about Microsoft Excel"