Vlookup in Excel userform is not working - combobox

I have a userform containing a combobox. Depending on the value of this combobox I want to fill a textbox in the same userform. I'm using the next code:
Private Sub ComboBox1_Afterupdate()
With Me
.TextBox4 = Application.WorksheetFunction.VLookup(Me.ComboBox1,
Sheets("Members").Range("B6:D15"), 2, 0)
End With
End Sub
Every time I try to run the userform I get a Runtime Error 1004 message.
What am I doing wrong?

Related

How to fix the late key press problem in access

I have a textbox that's purpose is to update the subtotal value whenever there is a key stroke in access.
Now the problem with this is that the OnKey press event function updates the subtotal value after 1 extra key press. The text box is named as QuantityOrdSub and it is the box that takes quantity, this text box multiplies it with the unit price (DLOOKUP function which works). The output must instantly go into SubTotalValue text box and it this textbox has a control source = Subtotal
Private Sub QuantityOrdSub_KeyPress(KeyAscii As Integer)
Me.SubTotalValue.Value = (DLookup("UnitPrice", "Stock", "StockID=" & Int(Me.StockSearchID.Value))) *
(Int(Me.QuantityOrdSub.Value))
End Sub
To restate, I am trying to update a text box instantly on key stroke.
Two problems:
1) The correct event to use is On Change, i.e. Private Sub QuantityOrdSub_Change, not KeyPress.
2) .Value of the textbox isn't updated until you leave the control. To get the entered text while the user is typing, you must use .Text, i.e. Me.QuantityOrdSub.Text.
If you want instant calculation, I wouldn't monitor the KeyPress() event. Instead, I would have the control report when its value changes, therefore I'd monitor the Change() event.
Private Sub QuantityOrdSub_Change()
With QuantityOrdSub
If Len(.Text) > 0 Then
SubTotalValue.Value = DLookup("UnitPrice", "Stock", "StockID=" & StockSearchID.Value) * Int(.Text)
End If
End With
End Sub

How to code "A2" to add to end of combobox in userform?

I have a userform that the user can input data regarding solar panels and it fills in sheet1. I am now trying to allow the user to input new data that will go to the end of the combobox in the userform. So for example, if they start using a new manufacterur, they can just type in the name of the manufacturer somewhere (right now in sheet 2) and I need to code it so it will end up at the end of the Manufacturer combobox in the userform. What is the most effective way to do this and how do I code it. The solution I'm looking for would be the user clicks on sheet 2, types in the new manufacturer, presses add, and it pops up at the end of the manufacturer combobox in the userform (userform1). Thanks.
sheet 1
userform

WPF application page doesn't update when I update the content of the labels

I'm writing a VB.Net WPF application which uses a frame on the MainWindow to show a page that contains multiple labels. I dynamically update those labels in my logic from the page but once those labels are updated, this doesn't reflect in the frame which shows the page.
This is the sub that updates the labels in Page2.xaml.vb:
Public Sub UpdateLabels(Name As String, microphonefinal As List(Of String))
Dim labelList As New List(Of Label)
For i As Integer = 0 To microphonefinal.Count - 1
For Each Label As Label In Page1Grid.Children
If Label.Name.Contains(Name) Then
Label.Content = microphonefinal(i)
Exit For
End If
Next
Next
End Sub
I call the above sub from MainWindow.xaml.vb using the following:
Dim form = New Page2
If microphonefinal.Count > 0 Then
form.UpdateLabels("Microphones", microphonefinal)
End If
I'm not sure if the issue is because I'm creating a new instance of Page2. But if I don't include this then I get the error: "Reference to a non-shared member requires an object reference".
I tried using frame.Refresh() to see if this would update the page with the new values in the labels but it doesn't. I've also used MsgBox to display the contents of the labels to make sure they've changed.
Am I doing something wrong? Or is there anything I'm missing? Please let me know if there's anymore information you need to help. Thank you!
I managed to access the sub UpdateLabels() of class Page2 by using the frame as you said. So to call the sub I coded it like this:
frame.Content.UpdateLabels("Microphones", microphonefinal)

How to Populate Label with String Array on ComboBox Item Selection in VB.Net

I have an application in VB.Net where I'm trying to fill a label with some string data that I have in an array. I have a ComboBox which holds some states as the index collection/values. When I select a particular value in the combobox, I want to pull string data from the assigned array, and populate the label with it as a "clickable link a browser window. I'm lost on this, yet here is what I have in my code stub:
Private Sub cboSelectState_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboSelectState.SelectedIndexChanged
'Create a string array
Dim AlabamaCities() As String = {"http://www.rolltide.com/", "http://www.crimsontidehoops.com/", "http://centralalabamapride.org/"}
Dim strAlabama As String
'Populate label with the array data, on a particular value selection in combo box.
If cboSelectState.SelectedValue("Georgia") Then
strAlabama = CStr(AlabamaCities(3))
lblLinkOutput.Text = strAlabama
End If
End Sub
So when I pick Alabama in my combo box, I want the label to show:
http://www.rolltide.com
http://www.crimsontidehoops.com
http://centralalabamapride.org
The links will be clickable from the label and populate in the same tab whenever clicked. I haven't tried the clickable link part yet, and I will try once I get this down.
I know it's probably bad starting form out the gate. But I'm trying to get the form down to gain the knowledge and plan out a bigger project, and accomplish something better when I think of it. I appreciate your knowledge and assistance.
Firstly, it would make sense to use a Dictionary to store the data. The state names will be the keys and the values would be the arrays of URLs. You would then display the keys in the ComboBox and, when a selection is made, use the selected key to get the corresponding value from the Dictionary.
At that point, you won't be using a Label if you want clickable links. You should use a TableLayoutPanel as a container and then add one LinkLabel to the table for each URL in the array. You can then use a single handler for all the LinkClicked events.

Create ComboBoxes automatically for every paragraph in ppt textbox

i am new to VBa and recently encountered the following problem: I copy data (rows) from an excel sheet into powerpoint and I want to make a combobox for every line (so for every row in excel) that i copy. All I could find was how to manually insert comboboxes via the menu in Powerpoint but i want to avoid having to add so many manually. Is there a way to add the comboboxes via VBA code?
Here is some of the code I use:
'Loop through each worksheet
For Each objSheet In ActiveWorkbook.Worksheets
'Create new slide for the data
Set pptSld = pptPre.Slides.Add(Index:=pptPre.Slides.count + 1, Layout:=ppLayoutText)
'Paste the data to the text box of each slide
objSheet.UsedRange.Copy
pptSld.Shapes(2).TextFrame.TextRange.Paste
'Formatting the text box 2
pptSld.Shapes(2).TextFrame.TextRange.ParagraphFormat.Bullet = msoTrue
pptSld.Shapes(2).TextFrame.TextRange.ParagraphFormat.Bullet.RelativeSize = 1
pptSld.Shapes(2).TextFrame.TextRange.Font.Size = 16
Next objSheet
How to continue? Want to define a combo box for each sheet row
I'm not clear on what the code you've posted has to do with adding combo boxes, but here's an example of how to add a combo box and add items to it:
Dim oSh As Shape
Dim oSl As Slide
Set oSl = ActivePresentation.Slides(1)
Set oSh = oSl.Shapes.AddOLEObject(Left:=168, Top:=24, Width:=192, Height:=24, ClassName:="Forms.ComboBox.1", Link:=msoFalse)
With oSh.OLEFormat.Object
.AddItem ("This")
.AddItem ("That")
.AddItem ("The Other")
End With

Resources