I've got an issue with my listbox. In the user form initialize event I'm using the following code to populate it:
RecordSelectionBox.List = WorkingCopy.Worksheets(1).Range("A2:P20").Value
Which works out fine. I have column width adjustments which also work out fine. Once the user has selected a record, a line from the listbox I'm setting the captions of a bunch of labels to the value of the listbox columns. It fills out label captions 1 to 15 just fine. When it hits 16 I get an error "Could Not Get the Column Property. Invalid Argument" "Run-time error '-2147024809 (80070057)'"
Here is the code:
Explanation.Caption = RecordSelectionBox.Column(16)
a debug.print of RecordSelectionBox.ColumnCount shows that I indeed have 16 columns. The explanation field is the longest of the fields I'm using, but I'm not sure that I see how that would become an issue. If anyone has an idea, I'm all ears.
That is because the First Column of the listbox starts with 0
Your first Label should be
Label1.Caption = RecordSelectionBox.Column(0)
and the 16th should be
Explanation.Caption = RecordSelectionBox.Column(15)
Related
Has anyone been able to get the time-phased work effort VBA extract macro by Jack Dalhgren, its quite an old macro.
I've been able to create the form and the macro works for the default timephase which is weeks, but if I select another say months I get an error on this line of code. (runtime error 13, type mismatch)
Set pTSV = ActiveProject.ProjectSummaryTask.TimeScaleData(tbstart.Value, tbend.Value, , cboxTSUnits.Value)
http://zo-d.com/blog/archives/programming/analyze-microsoft-project-resource-usage-data-in-excel.html
Thank you
The comboBox in the code uses 2 columns, the text and the internal representation which is a number. The code uses predefined constants for it like pjTimescaleWeeks. The call to TimeScaleData expects this number as parameter.
It is likely that you get the text (a String) as result from the comboBox, (eg "Week"), and this causes the Type mismatch.
You can specify that you want the value of the 2nd column as Value from the combobox. You can do this using the VBE form designer, set property BoundColumn to 2, or you can do this in you code:
Sub fillTSUnitsBox()
...
cboxTSUnits.List = myArray
cboxTSUnits.BoundColumn = 1
cboxTSUnits.Value = 3
End Sub
I am using a ListBox in a UserForm to display the data from a Table in my worksheets. All the data is correctly formatted in the table but in the ListBox, the currency is being displayed with an "error symbol" which should simply be a space (as per the french standard for currency formatting) and looks like the following :
I won't add the code for the UserForm since I am only having issues when inserting the data into the ListBox. However, below is the code responsible for populating said ListBox where msOperationTable is of type ListObject :
TableEntries.ColumnCount = 6
TableEntries.ColumnHeads = True
TableEntries.ColumnWidths = "100; 140; 150; 85; 100; 70"
TableEntries.RowSource = msOperationTable.Parent.Name & "!" & msOperationTable.DataBodyRange.Address
I haven't been able to find any explanation as to why this happens and I am starting to wonder if there is anything that can be done to fix this.
I have a userform in Excel. On loading, the form pulls data from the last row of a spreadsheet. There is a button on the form to print the form.
Prior to printing the form, it updates the selection in a list box for work order status to "Assigned" and then copies this status to the spreadsheet.
Sometimes the work order status in the spreadsheet is updated to "". It is like the selection of the list box is not being recognized. It is intermittent and I have not been able to determine a pattern.
This is the code
PrintWOForm.LB_WOStatus.value = "Assigned" 'Updates WO status to Assigned
To write this to the spreadsheet I have this code
'Update WO Status to Complete if there is a date in Date Completed
'Else update Status based on Selection in WO Status list box
If PrintWOForm.TB_DateComplete = "" Then
ws.Cells(cRow, 4) = PrintWOForm.LB_WOStatus.value
Else
ws.Cells(cRow, 4) = "Complete"
ws.Cells(cRow, 23) = PrintWOForm.LB_RepairCode.value
End If
It appears when I first open the form and use the print button, which updates the selection in the list box LB_WOStatus to "Assigned", it copies a blank into cRow 4.
If I manually select a status in the list box, that time and every time forward it will work correctly even when the status is selected by the code.
I am not sure this is best the fix for my issue, but so far it appears to work well. I added the below first line of code in front the prexesting second line of code.
Me.LB_WOStatus.SetFocus 'Must SetFocus to the WOStatus list box for the application to realize the next line of code
Me.LB_WOStatus.value = "Assigned" 'Updates WO status to Assigned
I did not try using the SetFocus method previously because I read on one of these websites that this was only used to set the focus to the object for the user of the form.
I have a VBA form which is used to enter data on a sheet. I am currently coding the form so as it will load any data already existing in the sheet back into the form.
For simple text strings it works perfectly.
e.g.
ReqSetup.ReqText = Application.Worksheets("Req Sheet").Range("F11").Value
However, I have some combo boxes, that on the form, when they are selected will enter a number in the corresponding cell.
Fail 1. - Run Time Error 380 - Invalid property value.
ReqSetup.MinPerKgCB = Application.Worksheets("Req Sheet").Range("C27").Value
Fail 2.
Dim MinPerKg As Range
Set MinPerKg = Application.Worksheets("Req Sheet").Range("C27")
ReqSetup.MinPerKgCB = MinPerKg
I'm obviously doing something really simple wrong but I can't work out what it is!!
Kind Regards!
I have some combo boxes, that on the form, when they are selected will
enter a number in the corresponding cell
Then you'd need to do the opposite of your code attempt, i.e.:
Worksheets("Req Sheet").Range("C27").Value = ReqSetup.MinPerKgCB.Value
That you'd better wrap inside a check that any combobox value is actually selected :
With ReqSetup.MinPerKgCB
If .ListIndex <> -1 Then Worksheets("Req Sheet").Range("C27").Value = .Value
End With
I have a listbox with 3 columns. In some rows there is no entry in the third column (it was never populated). I want to test whether the third column for a particular row has an entry, like this:
if listbox1.list(i,2) = "" then
But this gives a run time error if there is no entry in the third column. I have also tried
if isnull(listbox1.list(i,2)) then
but again this produces a run-time error. I know I can get around this by using on error resume next, but I have a feeling there must be a better way.
Edit:
The error I get is "Could not get the List property. Invalid argument.". In my actual code I refer to .list(i,j) and it works fine when j= 0 and j = 1, but when j = 2 it errors. In the example I am testing there are NO ENTRIES in column 2 of the listbox whatsoever, but the listbox's columncount property is set to a value of 3.
Here are two different ways:
If Len(Me.ListBox1.List(i, 2)) = 0 Then
If IsEmpty(Me.ListBox1.List(i, 2)) Then