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.
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 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
Excel VBA ListBox and ComboBox display wrong characters while TextBox provides the correct ones, using the same UserForm.
ListBox And ComboBox provides some Ansi substitute instead of Baltic characters, that is wrong.
I've changed:
charset of form and listBox from 133 into 163 by using ListBox.Font.Charset property
use of font Arial or Times New Roman with Baltic encoding
read through tons of pages on the internet and still no luck..
Thanks for your attention
I used code as follows:
Private Sub UserForm_Initialize()
UserForm2.Font.Charset = 186
ListBox1.List = Array("ĄČęėį", "Žųūįšų", 222) -> does not provide correct text :(
With ListBox1
.AddItem "Vilnius"
.AddItem "Kaunas"
.AddItem "Klaipėda" -> Klaipëda
.AddItem "Šiauliai" -> Ðiauliai
.AddItem Chr(222)
End With
Finally looks like VBA editor has trouble with international characters - if use button caption through Object Properties window - it goes wrong.
But entering labels and button text directly on the form provides correct outcome, hence there is a work around here - use RowSource option, taking data from excel table, which gives right encoding:
ListBox1.RowSource = "=Sheet2!A1:A5"
This solution is convenient to my needs and the question is closed by now.
Thank you for your response.
To populate ListBox and ComboBox with correct international characters I used Object Property window providing RowSource and taking data from Excel table.
In VBA editor it looks like this: ListBox1.RowSource = "=Sheet2!A1:A5"
Such an approach works well with Baltic and Russian languages, I did not try it with other languages.
My goal is to change the filter of 3 pivot tables, all with the same field with the click of a button attached to a macro.
Here is my code:
Dim pickedDate As String
Dim shift As String
pickedDate = Worksheets("Report").Range("C1").Value
shift = Worksheets("Report").Range("C2").Value
Worksheets("Report").PivotTables("PivotTable2").PivotCache.SourceData = Worksheets("Fullness").Range("A1").CurrentRegion.Address(, , xlR1C1, True)
Worksheets("Report").PivotTables("PivotTable3").PivotCache.SourceData = Worksheets("Backed").Range("A1").CurrentRegion.Address(, , xlR1C1, True)
Worksheets("Report").PivotTables("PivotTable4").PivotCache.SourceData = Worksheets("Hoist").Range("A1").CurrentRegion.Address(, , xlR1C1, True)
For Each PT In ActiveSheet.PivotTables
PT.PivotFields("Date").CurrentPage = CDate(pickedDate)
PT.PivotFields("Shift").CurrentPage = shift
Next
However when I get to my loop for the pivot tables, I get the error on PT.PivotFields("Date").CurrentPage = CDate(pickedDate)
:
Run time error 1004
Application Defined or Object Defined Error
I've verfied the source data for the tables is updated correctly.
I've tried not using the loop, and doing it manually like
Worksheets("Report").PivotTables("PivotTable4").PivotFields("Date").CurrentPage = CDate(pickedDate)
for each table, and it only works for one of the tables, my PivotTable3.
Even more curiously, when I comment out my code to change the date, and use either way (the loop or the manual change for the 3 tables) for the shift change it works perfectly with no error.
I've verfied the name of my pivot tables, that's not the issue. The name of the field I'm trying to change appears correct as well- it works for one of the tables and I've copied and pasted that cell "Date" into the others even.
What am I missing?
I'm not completely sure why this works now, but all I did to change my code was add into the loop a clear filter command for the "Date" field.
So now my code has this loop instead for making the date and shift change for all the pivot tables based on a cell value I enter manually, just once
For Each PT In ActiveSheet.PivotTables
PT.PivotFields("Date").ClearAllFilters
PT.PivotFields("Date").CurrentPage = CDate(pickedDate)
PT.PivotFields("Shift").CurrentPage = shift
Next
Again, I'm not sure why I didn't have to do this for the shift filter, but now it works. I suggest trying that first if anyone encounters this issue
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)