Hi All,
I have designed a jobsheet in excel and am using a user form to pick
parts from a list located on a different worksheet.
I have a quantity box on there with a spinbutton and when a control
button is pressed the parts and quantities are updated on the next
available empty line on my job sheet. I can manually type into the
combo box and all works great, but I cannot get the box to pick up any
parts from the worksheet.
The parts list will be modified frequently by others so I need to add
all items untill it comes across a blank line, or perhaps a flag at the
end of the list would be better???
Also, it would be handy if the pick list could jump to a section by
pressing the first letter key on the keyboard, can a combo box do that?
Heres what I have that doesnt work!
Private Sub cboPartsused_Click()
ActiveWorkbook.Sheets("temp parts").Activate
Range("A2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
AddItem.ActiveCell.Value
End If
Loop Until IsEmpty(ActiveCell) = True
End Sub
Now just to make things more complicated!
I have wrote macros that enable the job sheet to be closed without
prompting to be saved and before it closes, a new sheet is opened and
the values copied and pasted into it so the macros are not copied. Then
the filename contains the job number and date time stamp so the
filenames are not duplicated, and the files are saved into another
folder on the desktop.
This can be printed "on site" and given to the customer.
I would like all the info to go to another almost duplicate worksheet
except that on this one, the contents of 2 more columns (prices etc)
are placed in the jobsheet for invoicing purposes, but I dont want the
prices to appear in the combo box, only the colum A containing part
descriptions.
Can anyone out there help?
I am totally new to this VBA programming. The last time I programmed
anything was 15 years ago - basic and 6502!! I'm slowly getting back
into programming!
Thanks in advance!
Hi Kev,
for filling combobox with values you have in excel range (a2 .. last
populated row in column a) use something like this:
Private Sub cboPartsused_Click()
dim rng as range
set rng = range("a2")
userform1.combobox1.list=range(rng.address,rng.End(xlDown).Address).value
End Sub
Regards,
Ivan
Thanks for you Reply Ivan,
Would you be so kind as to explain how this works, a little so I might
adapt it into my sub?
(I'm easilly confused at the moment but working on it)
Thanks,
Kev
I think it should be
Private Sub cboPartsused_Click()
Dim rng As Range
Set rng = Range("a2")
Me.cboPartsUsed.List = Range(rng.Address, rng.End(xlDown).Address).Value
End Sub
all it does it build a range from A2 down to the ;last filled cell
(rng.End(xlDown).Address) and then loads those values into the list.
--
HTH
Bob Phillips
(remove nothere from the email address if mailing direct)
"Ivan Raiminius" <ivan.raiminius@fleurdesante.cz> wrote in message
news:1148045779.866295.144820@g10g2000cwb.googlegroups.com...
> Hi Kev,
>
> for filling combobox with values you have in excel range (a2 .. last
> populated row in column a) use something like this:
>
> Private Sub cboPartsused_Click()
> dim rng as range
> set rng = range("a2")
> userform1.combobox1.list=range(rng.address,rng.End(xlDown).Address).value
> End Sub
>
> Regards,
> Ivan
>
Hi Kev,
userform1 'name of the userform
combobox1 'name of the combobox
list 'property of the combobox, returns or sets the list entries of a
ListBox or ComboBox
rng 'object which is set to range("a2") - this is the cell which
contains first entry, that should be placed in the combobox (change to
suit your needs)
range(rng.address,rng.End(xlDown).Address).value 'rng.End(xlDown) -
finds the last cell below rng before empty cell, this is used to
construct range from a2 till the last non-empty cell bellow a2,
value(s) from this range are used to fill the combobox1
Please let me know if something is not clear.
Regards,
Ivan
Thank you both for you help.
I understand how it works, I dont know what I am doing wrong but I
cannot get it to work!!
Heres what I have there right now
Private Sub cboPartsused_Click()
'ActiveWorkbook.Sheets("temp parts").Activate
'AddItem.Range = Cells("a2:a12")
'ActiveWorkbook.Sheets("temp parts").Activate
'Range("A2").Select
'Do
'If IsEmpty(ActiveCell) = False Then
'ActiveCell.Offset(1, 0).Select
'AddItem.ActiveCell.Value
'End If
'Loop Until IsEmpty(ActiveCell) = True
'Dim rng As Range
'Set rng = Range("a2")
'cboPartsused.List = Range(rng.ActiveWorkbook.Sheets("temp parts"),
rng.End(xlDown).ActiveWorkbook.Sheets("temp parts")).Value
Dim rng As Range
Set rng = Range("a2")
Me.cboPartsused.List = Range(rng.Sheets("temp parts"),
rng.End(xlDown).Sheets("temp parts")).Value
End Sub
I have tried various methods and have ' them out and will obviously
dump them once this is de-bugged.
Have I got the address wrong?
Thank you.
Kev
Hi Kev,
if "temp parts" is name of sheet on which you have the list and a2 is
cell with first item of the list, then:
Dim rng As Range
Set rng = worksheets("temp parts").Range("a2")
Me.cboPartsUsed.List = Range(rng.Address,
rng.End(xlDown).Address).Value
Regards,
Ivan
Thanks again,
Tried this. Again, just get a blank combo box.
Could there be a problem somewhere else?
Thanks,
Kev
Hi Kev,
set breakboint in your code at line
Me.cboPartsUsed.List = Range(rng.Address,
rng.End(xlDown).Address).Value
and into immediate window (when the code stops), check for the proper
address and values:
?Range(rng.Address,rng.End(xlDown).Address).address 'should give you
proper address
?for each cell in Range(rng.Address,rng.End(xlDown).Address) :
debug.print cell.value : next cell 'should print the list of values
If these two checks give you proper address and list of values, then
proceed one step (by pressing F8) and check the combobox for values.
?for i = 0 to Me.cboPartsUsed.List.count - 1 : debug.print
Me.cboPartsUsed.List(0,i) : next i
Let me know the results.
Regards,
Ivan
I have tried this and nothing is different!
I have inserted a breakpoint by clicking debug then toggle breakpoint.
I run the code and nothing has changed.
Any ideas for this novice?
Thanks Ivan,
Kev
Hi Kev,
1) did you set breakpoint at the correct row?
2) what is the result from immediate window after executing the checks?
Regards,
Ivan
Morning Ivan,
I dont understand the procedure or where to find the window etc
.. I placed my cursor at the begining of the line you stated then
pressed debug etc.
I then used the run command. The user form came up as normal and run as
normal. The combo box displays a blank box underneath when pressed, but
nothing else happens.
Cheers
Kev
Hi Kev,
in VBA window you should see window called immediate, otherwise go to
view >> immediate window.
When the code stops at the breakpoint (the application will bring you
to vbe window), you should see the line of code with yellow background
and should be able to execute commands from previous post in immediate
window (just copy and paste them, you need to press enter at each row
of code to execute the row in immediate window).
You need to click on your userform at "cboPartsused" to fire event
"Private Sub cboPartsused_Click" - the breakpoint is inside this event
procedure.
Regards,
Ivan
Sory Ivan,
The code doesnt seem to be stopping at the breakpoint. The combo box
stays on the screen with the cursor flashing. I can click the drop down
arrow to the right and a blank box appears, but this is endless. There
is nothing in the immediate window which I have now found.
I have tried to execute your commands, but get an error message -
object required which leads me to believe that no values are set!
I know it's me thats doing something wrong and I will learn from
this!!!
Cheers,
Kev
Hi Kev,
nothing to be sorry about.
Seems to me like Private Sub cboPartsused_Click never runs.
replace _Click with _DropButtonClick to see what happens (it should run
when you click on dropdown button on the combobox).
Regards,
Ivan
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks