|
-
Mar 15th, 2006, 11:58 AM
#1
Thread Starter
New Member
Combo Boxes
I have a combo box in a userform linked to a rowsource. I also have a macro in the userform. What I want to happen is when the combo box has selected an item and the button is clicked I want the item selected to be deleted and the cell to the right of it too.
For example..
Rowsource
A1
A2
A3
A4
A5
In the combo box I picked cell A3. When I press the button I want the content of cell A3 and B3 deleted.
Last edited by TheRealDave; Mar 15th, 2006 at 05:23 PM.
-
Mar 15th, 2006, 12:41 PM
#2
Addicted Member
Re: Combo Boxes
Hi, TheRealDave
Paste this code to your Button Click event:
VB Code:
Dim address As Range
Set address = Range(ComboBox1.Value)
address.Select
address.ClearContents
address.Offset(0, 1).Select
Selection.ClearContents
hope this help
regards,
sweet_dreams
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts. 
-
Mar 15th, 2006, 12:48 PM
#3
Addicted Member
Re: Combo Boxes
i optimalized my previous code now looks better 
VB Code:
Range(ComboBox1.Value).Select
Range(ActiveCell, ActiveCell.Offset(0, 1)).ClearContents
regards,
sweet_dreams
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts. 
-
Mar 15th, 2006, 12:49 PM
#4
Thread Starter
New Member
Re: Combo Boxes
You make it seem so easy! That's a great help, thanks!
-
Mar 15th, 2006, 12:51 PM
#5
Addicted Member
Re: Combo Boxes
i suggest you use this second code. and don't forget to tick thread as resolved (if of course it is resolved )
regards,
sweet_dreams
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts. 
-
Mar 15th, 2006, 01:07 PM
#6
Thread Starter
New Member
Re: Combo Boxes
will do. off to try it now
-
Mar 15th, 2006, 04:26 PM
#7
Thread Starter
New Member
Re: [RESOLVED] Combo Boxes
ahh damn.. marked it resolved when it isnt.
I get "run time error '1004':
Method 'Range' of object '_Global' failed."
-
Mar 15th, 2006, 04:44 PM
#8
Addicted Member
Re: [RESOLVED] Combo Boxes
hm, on my PC this code works perfect:
VB Code:
Range(ComboBox1.Value).Select
Range(ActiveCell, ActiveCell.Offset(0, 1)).ClearContents
make sure that values of cell addresses in your RowSource property are correct
s_d
-
Mar 15th, 2006, 04:50 PM
#9
Thread Starter
New Member
Re: [RESOLVED] Combo Boxes
I have the control source set to Sheet!A1 and the rowsource to sheet!List
where the list selects column A
any problems?
Last edited by TheRealDave; Mar 15th, 2006 at 04:53 PM.
-
Mar 15th, 2006, 04:53 PM
#10
Addicted Member
Re: [RESOLVED] Combo Boxes
are you using any other code in your macro??? can you paste the whole code you are using???
oh and have you changed the name of your combobox in the code???
s_d
-
Mar 15th, 2006, 04:55 PM
#11
Thread Starter
New Member
Re: [RESOLVED] Combo Boxes
that's the only code in there. It's very basic. I have different pages in a userform with the combo box and button on each page. I think the problem is selecting the cell somewhere but I just cant figure it out
-
Mar 15th, 2006, 04:58 PM
#12
Addicted Member
Re: [RESOLVED] Combo Boxes
the code which I gave you is selectiond cell with address which was choosen in combobox: so if you clicked in your combobox A1 value, code selects A1 cell and then selects range A1:B1 and clear it's content.
well, I don't have the foggiest idea what's wrong.
-
Mar 15th, 2006, 05:02 PM
#13
Thread Starter
New Member
-
Mar 15th, 2006, 05:03 PM
#14
Addicted Member
Re: [RESOLVED] Combo Boxes
you don't need to set control source property, row source is enought if you only want to assign list of values to your combobox
hm I don't understand wha you mean by saying:
where the list selects column A
try row source property as for eg sheet1!a1-a11
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts. 
-
Mar 15th, 2006, 05:09 PM
#15
Thread Starter
New Member
Re: [RESOLVED] Combo Boxes
what i meant by that is the list was the entire column A. This was because there was to be an unlimited ammount in that column and it had be selected within the system. I just tried removing the control source and am still getting the error. It's ok though, should be alright for me to just do it as it is.
-
Mar 15th, 2006, 05:12 PM
#16
Addicted Member
Re: [RESOLVED] Combo Boxes
how did you create this list ??? I think here could be a problem
-
Mar 15th, 2006, 05:15 PM
#17
Thread Starter
New Member
Re: [RESOLVED] Combo Boxes
Went to the sheet. Pressed A to select the whole column (which works fine in other places) and named it using the name box. Like I said, it's used as i list in validation on another page so there's no error in the list itself as far as I can tell.
-
Mar 15th, 2006, 05:19 PM
#18
Addicted Member
Re: [RESOLVED] Combo Boxes
where do you exactly get the error message ???
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts. 
-
Mar 15th, 2006, 05:23 PM
#19
Thread Starter
New Member
Re: [RESOLVED] Combo Boxes
Isn't that. I can still view the list. The correct property I have for that is "PERIPHERALS!PSR" where the sheet name is PERIPHERALS and the list is PSR.Not sure if this one's going to be solved
-
Mar 15th, 2006, 05:24 PM
#20
Addicted Member
Re: Combo Boxes
maybe attach your excel file so I can take a look at it in the morning I'm too tired to do this now.
regards,
sweet_dreams
-
Mar 15th, 2006, 05:27 PM
#21
Thread Starter
New Member
Re: Combo Boxes
That will be a problem as i don't have it with me. It's on a different computer that i have remote access to and no way of moving it, sorry. I think i'm just going to leave it and see how it goes..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|