Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 267
Default combo boxes (swines)

Am trying to get a combo box to keep adding its selected contents to a cell
(actually to an offset cell) have used this sub successfully with a set list
fill range but as soon as I use a variable range it becomes circular and just
keeps adding and adding to itself etc! how do I make a cell = itself plus
another cell once only per combo box click?

Private Sub ComboBox54_Click()

With Worksheets("Main Board")

Set c = .Range("D82")

ActiveCell.Offset(c, 0).Value = Range("I86") + ActiveCell.Offset(c, 0).Value
Range("I86") = " "
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default combo boxes (swines)

On May 1, 10:54 am, Atishoo wrote:
Am trying to get a combo box to keep adding its selected contents to a cell
(actually to an offset cell) have used this sub successfully with a set list
fill range but as soon as I use a variable range it becomes circular and just
keeps adding and adding to itself etc! how do I make a cell = itself plus
another cell once only per combo box click?

Private Sub ComboBox54_Click()

With Worksheets("Main Board")

Set c = .Range("D82")

ActiveCell.Offset(c, 0).Value = Range("I86") + ActiveCell.Offset(c, 0).Value
Range("I86") = " "
End With

End Sub


Try saving the sum into an intermediate temporary value ...

Private Sub ComboBox54_Click()
Dim Newvalue, c
With Worksheets("Main Board")

Set c = .Range("D82")
Newvalue = Range("I86") + ActiveCell.Offset(c, 0).Value

ActiveCell.Offset(c, 0).Value = Newvalue
Range("I86") = ""
End With

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default combo boxes (swines)

There should be no problem with adding another cell value to the first cell
value to increase the first cell value. That said, in your code you use the
Set statement for a cell, which makes that Set value an object variable. You
then use the object variable in a relative cell reference like Offset(c, 0).
This can cause problems because of data type. If you are going to use the
variable c as a number value contained in the cell D82 then you don't need
the Set statement, just use:

c = Range("D82").Value

That assumes that the value will be a number which can function in the
Offset statement.

I think your problem lies elsewhere. If you have a Worksheet_Change macro
in the sheet you are working on, then it is probably tiggering a calculation
when you click the button and sets off a chain reaction. Everytime the cell
adds the offset value it triggers the worksheet change event and on an on and
on.

"Atishoo" wrote:

Am trying to get a combo box to keep adding its selected contents to a cell
(actually to an offset cell) have used this sub successfully with a set list
fill range but as soon as I use a variable range it becomes circular and just
keeps adding and adding to itself etc! how do I make a cell = itself plus
another cell once only per combo box click?

Private Sub ComboBox54_Click()

With Worksheets("Main Board")

Set c = .Range("D82")

ActiveCell.Offset(c, 0).Value = Range("I86") + ActiveCell.Offset(c, 0).Value
Range("I86") = " "
End With

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 267
Default combo boxes (swines)

Thanks I changed the set c as suggested and that resolved a problem with two
combo boxes interfering with each other! The offset function is operating
exactly as you describe and works well! I think you are right about the
problem lying with a change macro somewhere I have previously deleted a shed
load of old VBA in this project but cant find any change macro's left might
they be hidden in some strange locaion deep in the bowels of vis basic? and
if i just delete the piece of code does that fully remove the macro?

"JLGWhiz" wrote:

There should be no problem with adding another cell value to the first cell
value to increase the first cell value. That said, in your code you use the
Set statement for a cell, which makes that Set value an object variable. You
then use the object variable in a relative cell reference like Offset(c, 0).
This can cause problems because of data type. If you are going to use the
variable c as a number value contained in the cell D82 then you don't need
the Set statement, just use:

c = Range("D82").Value

That assumes that the value will be a number which can function in the
Offset statement.

I think your problem lies elsewhere. If you have a Worksheet_Change macro
in the sheet you are working on, then it is probably tiggering a calculation
when you click the button and sets off a chain reaction. Everytime the cell
adds the offset value it triggers the worksheet change event and on an on and
on.

"Atishoo" wrote:

Am trying to get a combo box to keep adding its selected contents to a cell
(actually to an offset cell) have used this sub successfully with a set list
fill range but as soon as I use a variable range it becomes circular and just
keeps adding and adding to itself etc! how do I make a cell = itself plus
another cell once only per combo box click?

Private Sub ComboBox54_Click()

With Worksheets("Main Board")

Set c = .Range("D82")

ActiveCell.Offset(c, 0).Value = Range("I86") + ActiveCell.Offset(c, 0).Value
Range("I86") = " "
End With

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 267
Default combo boxes (swines)

Oh yes forgot to mention Im not actually adding values together but am
combining text so if i select "john" from the combo box it will put "john" in
a cell offset to the active cell, then if i select "Peter" It will return
"john Peter" in the offset cell etc etc until I use a clear vba to reset the
offset cell

"JLGWhiz" wrote:

There should be no problem with adding another cell value to the first cell
value to increase the first cell value. That said, in your code you use the
Set statement for a cell, which makes that Set value an object variable. You
then use the object variable in a relative cell reference like Offset(c, 0).
This can cause problems because of data type. If you are going to use the
variable c as a number value contained in the cell D82 then you don't need
the Set statement, just use:

c = Range("D82").Value

That assumes that the value will be a number which can function in the
Offset statement.

I think your problem lies elsewhere. If you have a Worksheet_Change macro
in the sheet you are working on, then it is probably tiggering a calculation
when you click the button and sets off a chain reaction. Everytime the cell
adds the offset value it triggers the worksheet change event and on an on and
on.

"Atishoo" wrote:

Am trying to get a combo box to keep adding its selected contents to a cell
(actually to an offset cell) have used this sub successfully with a set list
fill range but as soon as I use a variable range it becomes circular and just
keeps adding and adding to itself etc! how do I make a cell = itself plus
another cell once only per combo box click?

Private Sub ComboBox54_Click()

With Worksheets("Main Board")

Set c = .Range("D82")

ActiveCell.Offset(c, 0).Value = Range("I86") + ActiveCell.Offset(c, 0).Value
Range("I86") = " "
End With

End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default combo boxes (swines)

If you are trying to concatenate cell I86 value to the offset value then:

ActiveCell.Offset(c, 0).Value = Range("I86").Value & " " & _
ActiveCell.Offset(c, 0).Value

This will put John and Peter in the same cell with a space between the two.
If you don't want the space then:

ActiveCell.Offset(c, 0).Value = Range("I86").Value & ActiveCell.Offset(c,
0).Value

Use the ampersand (&) instead of plus (+) to concatenate strings. Use the +
to add numbers. It avoids confusion.

"Atishoo" wrote:

Oh yes forgot to mention Im not actually adding values together but am
combining text so if i select "john" from the combo box it will put "john" in
a cell offset to the active cell, then if i select "Peter" It will return
"john Peter" in the offset cell etc etc until I use a clear vba to reset the
offset cell

"JLGWhiz" wrote:

There should be no problem with adding another cell value to the first cell
value to increase the first cell value. That said, in your code you use the
Set statement for a cell, which makes that Set value an object variable. You
then use the object variable in a relative cell reference like Offset(c, 0).
This can cause problems because of data type. If you are going to use the
variable c as a number value contained in the cell D82 then you don't need
the Set statement, just use:

c = Range("D82").Value

That assumes that the value will be a number which can function in the
Offset statement.

I think your problem lies elsewhere. If you have a Worksheet_Change macro
in the sheet you are working on, then it is probably tiggering a calculation
when you click the button and sets off a chain reaction. Everytime the cell
adds the offset value it triggers the worksheet change event and on an on and
on.

"Atishoo" wrote:

Am trying to get a combo box to keep adding its selected contents to a cell
(actually to an offset cell) have used this sub successfully with a set list
fill range but as soon as I use a variable range it becomes circular and just
keeps adding and adding to itself etc! how do I make a cell = itself plus
another cell once only per combo box click?

Private Sub ComboBox54_Click()

With Worksheets("Main Board")

Set c = .Range("D82")

ActiveCell.Offset(c, 0).Value = Range("I86") + ActiveCell.Offset(c, 0).Value
Range("I86") = " "
End With

End Sub

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
Getting Combo boxes to change options based on other Combo boxes. Ancient Wolf New Users to Excel 1 March 27th 09 06:29 PM
Selecting subsets using combo boxes or list boxes CLamar Excel Discussion (Misc queries) 0 June 1st 06 07:43 PM
Questions on combo boxes and list boxes. Marc New Users to Excel 1 March 14th 06 09:40 AM
Filtered list for Combo Box ListFillRange - Nested Combo Boxes DoctorG Excel Programming 3 February 23rd 06 12:15 PM
List boxes/combo boxes Tibow Excel Programming 3 February 17th 04 12:35 PM


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