im not really sure how to word this but im going to try to describe the issue.
I am building a simple excel spreadsheet to keep track of my spending. each cost i input needs to be classified into a category. I have about 20 different categories and forget what they are.
Rather than scrolling up I would like to script a continuous suggestion prompt when i select a cell in a specific column of the spreadsheet. I want to just be able to read off the suggestion as to which category to input (manually).
See nothing too complex, i just know very little about vba syntax and how to phrase the issue. I think i need like a continuous running sub? again not sure what that is called.
Any help is appreciated.
Thank you
Ken
You could you a simple userform to select and parse data selection into the row you clicked.
First use an Event when you click in the column you want the reminder to pop up in. In this case I choose "D".
Private Sub Worksheet_Change(ByVal Target As Range)
Dim arr
If Not Intersect(Target, Range("D:D")) Is Nothing Then
Application.EnableEvents = 0
UserForm1.Show
Target = a
Application.EnableEvents = 1
End If
End Sub
Then load the user form with your reminder data and select the reminder data you need from a userform combobox.
Private Sub UserForm_Initialize()
Dim arr
arr = Array("Unit1", "Unit2", "Unit3", "Unit4", "Unit5", "Unit6", _
"Unit7", "Unit8", "Unit9", "Unit10", "Unit11", "Unit12", _
"Unit13", "Unit14", "Unit15", "Unit16", "Unit17", "Unit18", _
"Unit19", "Unit20")
Me.ComboBox1.List = arr
End Sub
Private Sub ComboBox1_Change()
a = ComboBox1.Value
Unload Me
End Sub
And you will need to put a public variable in a standard module to store the data you want pasted in your sheet.
Public a As String
Be sure to change any control names to suit you.
Related
I am using a calendar created by Siddharth Rout found here:How can I create a calendar input in VBA Excel?
I have a userform that sits on top of a basic database that has a number of date fields.
I would like to use the one calendar form multiple times, i.e. have a cmdbutton1 on the userform that calls the calendar and puts the date in a label1, and then a cmdbutton2 that calls the same calendar form to populate label2. Obviously these will have different dates.
I have tried to do various forms of temporary binding to variables and nothing has worked. Any help would be appreciated!
You can create instances of the UserForm, set these up when you want and display when you need. From these instances you can modify the child userform
Private Sub CommandButton1_Click()
Dim ufrm2 As UserForm2
Set ufrm2 = New UserForm2
ufrm2.Label1.Caption = Me.CommandButton1.Caption
ufrm2.Show
End Sub
Private Sub CommandButton2_Click()
Dim ufrm2 As UserForm2
Set ufrm2 = New UserForm2
ufrm2.Label1.Caption = Me.CommandButton2.Caption
ufrm2.Show
End Sub
Giving:
I was looking at this question, and I think I have found the answer #Pete_B_C was looking for. I have added some code to the Userform "frmCalendar" to get the desired result.
'~~> Insert Selected date
Private Sub DTINSERT_Click()
If Len(Trim(Label6.Caption)) = 0 Then
MsgBox "Please select a date first", vbCritical, "No date selected"
Exit Sub
End If
*'~~> Change the code here to insert date where ever you want
If UserForm1.Visible = True Then
'do something
UserForm1.TextBox1 = Label6.Caption
End If
If UserForm3.Visible = True Then
'do something
UserForm3.TextBox12 = Label6.Caption
End If*
Unload Me
End Sub
I have used the option to hide and show the Userforms depending on which Userform is being used. If anyone knows how to do this in a better way than the way I have figured it, please let me know
I have looked at some examples for my question but couldn't find an answer that works.
Background:
I have a list of items (let's say apple, orange, banana) in Sheet1 (A2:A77, which is already a defined range with the name "Liste").
I then have on another sheet (Let's say Sheet2) with several cells where a userform (created with vba code) pops up where the user can choose an item and click OK.
However, due to the nature of the userform (and the list), you can have spelling errors etc and it will still be accepted. So I would like to create a check where it matches the input to the given list (to prevent users from putting anything else in). The userform/code is on purpose to keep it searchable (rather than just a simple data validation list).
Issue:
I tried to create this with vba code that checks the input, matches it to the Sheet1 list and if there is no match, shows a msgbox with a statement. This partially worked (for some letters but not others, very strange).
Here is the code I had:
Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim rSearchRng As Range
Dim vFindvar As Variant
If Not Intersect([B7:B26], Target) Is Nothing Then
Set rSearchRng = Sheet4.Range("Liste")
Set vFindvar = rSearchRng.Find(Target.Value)
If Not vFindvar Is Nothing Then
MsgBox "The Audit Project Name you have entered is not valid. Please try again!", vbExclamation, "Error!"
Selection.ClearContents
End If
End If
Application.EnableEvents = True
End Sub
So I was thinking of creating this error message instead with a simple data validation.
Data validation
I have tried the "list" option (and put it equal to the named range) but that did nothing (no error box showed up)
I have tried "Custom" with the following formula 'SUMPRODUCT(--(B12=Liste)>0)=TRUE (I found this on a post which worked for others when I tried it in the cell it gave me the expected "TRUE/FALSE" results) but still nothing shows up
UPDATE
Tigeravatars data validation recommendations work if you don't have a userform (see comments below).
For it to work with a UserForm, I changed the 'MatchEntry' to TRUE and also deleted any unwanted "change events" from my ComboBox code. The final code I use now is below:
Dim a()
Private Sub CommandButton2_Click()
End Sub
Private Sub UserForm_Initialize()
a = [Liste].Value
Me.ComboBox1.List = a
End Sub
Private Sub ComboBox1_Change()
Set d1 = CreateObject("Scripting.Dictionary")
tmp = UCase(Me.ComboBox1) & "*"
For Each c In a
If UCase(c) Like tmp Then d1(c) = ""
Next c
Me.ComboBox1.List = d1.keys
Me.ComboBox1.DropDown
End Sub
Private Sub CommandButton1_Click()
ActiveCell = Me.ComboBox1
Unload Me
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
I thought I show it here in case anyone stumbles across my question.
Thank you!
Select your cells where you want to put the data validation
With the cells selected, go to Data Tab -> Validation
Set "Allow" to "List" and set the Source to =Liste as shown here:
Next go to the "Error Alert" tab and set "Style" to "Warning" and enter the desired text in "Title" and "Error Message" as shown here:
Test it out. You should now have a drop-down list of valid choices, and if you attempt to manually enter an invalid choice you'll get the error message you specified.
As a note, if you want the data validation to completely disallow/prevent any entry not in the list, you'll need to set the Error Allert -> Style to be "Stop" instead of "Warning".
EDIT:
Per comments, it can't be a drop-down list. I highly recommend using a drop-down list for this because it will be the most effective way to cut down on time entering data as well as reduce errors from typos. However, if it absolutely cannot be a drop-down list, then you can use a Custom Data Validation and set the formula to =ISNUMBER(MATCH(B7,Liste,0)) (we are using B7 here because it is the first cell in the range of cells that contains this data validation).
Try the following formula:
=NOT(ISERROR(FIND("-"&A1&"-",(TEXTJOIN(,"-",TRUE,Sheet1!A1:A77)))))
That combines all the texts and then see if what's in the cell occurs in the list. I put it between dashes to prevent it from accepting partials.
I have an Excel WorkBook with several Sheets. I would like to be able to select from a drop down list in the "Home" Sheet and after selection is made, automatically switch to the proper Sheet and select a specific Cell.
It appeared to be easy, but I have failed time and again to make it work.
Here is an example of what I would like to do:
The only code that I managed to have a little success with is the following:
Private Sub Worksheet_Activate()
With Sheets("Home")
If Cells(6, 3).Value = "A" Then
Sheets("A").Select
ActiveSheet.Range("B7").Select
End If
End With
End Sub
The problem with it is that it will not check for the value until the user moves to another sheet. Then when it comes back, it will check for it, and will take it to the correct one, but the user will be stuck in a loop without being able to go back to "Home". (I know that it will only work on cell C6, but I just wanted to try if it worked before changing the Range)
You need the worksheet change event, rather than activate. Try this, in the Home sheet module.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$6" Then
Application.Goto Sheets(Target.Text).Range("B7")
End If
End Sub
I have a worksheet that runs a weightlifting meet. Last year I had created a tab that would give information on the current lifter and on who was lifting next.
left side - Display, right side - input tab
When I input an "x" in columns R, S, T, or W on the data tab, it changes the information in the BenchGenerator tab, like so:
Updated Display tab
What I want to do is make a userform display to run on a different screen so people can see this information. I had accomplished this last year by widening excel and using two view windows - display on the second screen and running the meet on the computer. It was ok but very clunky looking. With a floating userform tab, it would look fantastic. I am new to this, but got the form floating:
Private Sub Worksheet_Change(ByVal Target As Range)
UserForm1.Show (vbModeless)
End Sub
And got the labels to initially populate:
Userform Display
Using this code:
Private Sub UserForm_Activate()
UserForm1.Label1.Caption = Sheets("BenchGenerator").Range("c4").Value
UserForm1.Label2.Caption = Sheets("BenchGenerator").Range("c5").Value
UserForm1.Label3.Caption = Sheets("BenchGenerator").Range("c6").Value
UserForm1.Label4.Caption = Sheets("BenchGenerator").Range("d3").Value
UserForm1.Label5.Caption = Sheets("BenchGenerator").Range("d4").Value
UserForm1.Label6.Caption = Sheets("BenchGenerator").Range("d5").Value
UserForm1.Label7.Caption = Sheets("BenchGenerator").Range("d6").Value
End Sub
What it doesn't currently do is update the captions when I input the "x" in the data tab.
As I mentioned, this is my first foray into userforms and looking through mountains of code trying to figure this out, it will not be my last as there is lots to accomplish with them.
Thanks in advance for any help!
You're pretty close to getting this to work. The problem is that your calling a new form every time a change occurs.
Declare your form as an object outside of the Sub that creates (Show) it.
You can then access it to update labels from another Sub that has the same scope.
Create an UpdateForm sub for example and call it from your Worksheet_Change event.
Try this, place the following code in a new Module:
Dim myForm As Object
Sub launchForm()
Set myForm = UserForm1
myForm.Show (vbModeless)
End Sub
Sub updateForm()
Dim wks As Worksheet
Set wks = Sheets("BenchGenerator")
'Update label values here
myForm.Label1.Caption = wks.Range("C4").Value
myForm.Label2.Caption = wks.Range("C5").Value
myForm.Label3.Caption = wks.Range("C6").Value
myForm.Label4.Caption = wks.Range("D3").Value
myForm.Label5.Caption = wks.Range("D4").Value
myForm.Label6.Caption = wks.Range("D5").Value
myForm.Label7.Caption = wks.Range("D6").Value
End Sub
If you use Worksheet_Change to update the form you'll want to verify the form exist or just skip any errors in the event if it doesn't.
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
updateForm
End Sub
Not sure if there is an easier way to do it, but I made a concatenation routine to batch out my label setup and updates to quickly create/copy/paste all the code.
Just in case anyone didn't know how to do this
Cant seem to find the answer to this, I need a combobox (which is inside a userform) that has three selection
eg Rental,Purchase and Finance
Which the selected input is then put into example cell A1. I know how to do this if I have the list already on my excel sheet, but I don't want the list on the excel sheet only the selection. so I suppose I'm asking for a coded list of option inside the module which then outputs the result in to a cell.
Any help would be appreciated (I'm a Newbie)
Thanks
Basic code in the userform:
Private Sub ComboBox1_Change()
If me.combobox1.listindex > -1 then sheets("Sheet name").Range("A1").value = me.combobox1.Value
End Sub
Private Sub UserForm_Initialize()
Me.ComboBox1.List = Array("Rental", "Purchase", "Finance")
End Sub