Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default using a worksheet range to populate a combo box in excel

Hi Kev,

the runtime error is because I supposed, that there is at least one
non-blank cell below A23. Now I added check for it. I hope I understood
correctly locations for all the data.

Private Sub cmdAdd_Click()
Dim rng1 As Range
Dim rng2 As Range
Dim i As Long
'ActiveWorkbook.Sheets("Financial copy").Activate
Set rng1 = Sheets("Financial copy").Range("A23").End(xlDown)
If rng1.Row = Application.Rows.Count Then
Set rng1 = Sheets("Financial copy").Range("A23")
End If
Set rng2 = Worksheets("customer copy").Range("a1").End(xlDown)
If rng2.Row = Application.Rows.Count Then
Set rng2 = Worksheets("customer copy").Range("a1")
End If
With rng1
For i = 0 To cboPartsused.ColumnCount - 1
..Offset(1, i).Value = cboPartsused.List(cboPartsused.ListIndex, i)
Next i
..Offset(1, i).Value = txtQuantity.Value
rng2.Offset(1, 0).Resize(1, 2).Value = .Offset(1, 0).Resize(1, 2).Value

'added this row to copy result from ComboBox
rng2.Offset(1, 2).Value = txtQuantity.Value
End With
txtQuantity.Value = 1 'consider using number 1 instead of string
"1"
cboPartsused.listindex=-1
' Range("A1").Select
End Sub

Now I suppose that you will change your combobox to contain 4 columns
of data from Temp Parts (Part description, Part number, Trade price and
list price). If will get lost in achieving this, please post the code
that you use for initializing the combobox.

Regards,
Ivan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default using a worksheet range to populate a combo box in excel

Thanks Ivan,

I can see you have put some thought into the code your supplying me and
I appreciate your help.

I'm not sure how to initialize the combobox.

This is the only code I have!

Private Sub UserForm_Initialize()

txtQuantity.Value = "1"
cboPartsused.Value = ""
cboPartsused.SetFocus
spnButton1.Min = "1"

End Sub

I would appreciate your help here!

Nearly done now (I hope)!

Thank you,

Kev

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default using a worksheet range to populate a combo box in excel

Hi Kev,

sorry for replying so late, too busy now.

in code we did together:

Dim rng As Range
Set rng = worksheets("temp parts").Range("a2")
Me.cboPartsUsed.List = rng.parent.Range(rng.Address,
rng.End(xlDown).Address).Value

replace "Set rng = worksheets("temp parts").Range("a2")" with "Set rng
= worksheets("temp parts").Range("a2..d2")" probably - "a2..d2" is the
location of first data in "temp parts" sheet.

Set columncount in properties of combobox cbopartsused to 4. Then your
combobox will show four columns of data. If you don't want some of them
to display, set accordingly columnwidths in properties of cbopartsused.

Regards,
Ivan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default using a worksheet range to populate a combo box in excel

Ivan,

Don't know if you will get this, I used the reply button as usual, but
have been directed elsewhere!

Dont worry about taking time over this, I dont expect an immediate
response, seeing as though I'm getting free consultancy here - I'm
gratefull for whatever information I get, and I respect the fact that
you must be doing something full time elsewhere.


Okay, it nearly works apart from one or two things.

If I leave the combo box blank, I get, "runtime error 381, could not
get the list property, invalid property array index".

The cell a24 was selected as the first cell. I have corrected this
changing the reference in the code to a22. Also the data on finantial
copy needs to go from a23 onwards, so I changed the reference here from
a1 to a22 as well.

The code works on the financial copy twice only. What happens here is
cell a23 gets the first part, cell a24 gets the next, from then on cell
a24 updates instead of moving onto cell a25.

There is nothing happening in the financial copy at all!

Just a minor bug I know, but I cant get my head round it.

Thanks again,

Kev

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
Combo Box to populate variable output range DougL Excel Discussion (Misc queries) 5 February 1st 08 08:09 PM
Best way to populate worksheet from 2 combo boxes jswasson Excel Worksheet Functions 0 July 7th 06 01:21 PM
Selectively Populate Excel VBA Combo Box ll Excel Programming 1 May 4th 06 10:13 PM
Populate a combo box from a worksheet with VBA Jack Excel Programming 1 January 13th 06 12:44 PM
Using a specific range to populate a list/combo box tanktata[_2_] Excel Programming 3 January 7th 04 09:45 PM


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