Hello,
I really need some help on this. So, basically what I am trying to do is to create an inventory control sheet. I have many buttons on a spreadsheet (IN and OUT, all in column A) that when IN is pressed I want IN to apear in column D and the row coresponding to the button that was pushed. I also want the user to be prompted with an input box to enter the employee number and then have it placed in E and the coresponding row for that button. Any help on this would be greatly apriciated.
Last edited by Absent; 01-27-2012 at 02:45 PM.
Hi Absent
Assign this code to your Command ButtonOption Explicit Sub test() Dim r As Range Dim eNumber As String Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell eNumber = Application.InputBox _ (Prompt:="Please enter your Employee Number.", _ Title:="Employee Number", Type:=2) If eNumber = "" Then MsgBox "Please Enter Your Employee Number" Exit Sub Else Range(Cells(r.Row, 5), Cells(r.Row, 5)).Value = eNumber End If Range(Cells(r.Row, 4), Cells(r.Row, 4)).Value = ActiveSheet.Buttons(Application.Caller).Characters.Text End Sub
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
that solves my problem a bit, in terms of that the button will alow me to copy it to all rows and will stay with its respective row. but i have two butons, and in button and an out button. I have 100 rows. so far i have ahd to right 100 vba for the in button and 100 for the out button.
the in button code i have so far is---
Sub Check_IN_2()
'
' Check_IN Macro
'
'
Range("$D2").Select
ActiveCell.FormulaR1C1 = "IN"
Range("E2").Select
Selection.ClearContents
End Sub
and the code i have for the out button is ----
Sub Check_out_2()
'
' Check_out Macro
'
'
Range("$D2").Select
ActiveCell.FormulaR1C1 = "OUT"
Dim MYNUMBER
MYNUMBER = InputBox("Please Enter Employee Number", "MY NUMBER INPUT BOX")
Range("E2").Value = MYNUMBER
End Sub
i know there is a way to consolidate all these lines into one code that will run dynamically and prevent me from having to write them all into 200 different macros
jaslake,
also the code that you wrote writes "Button 6" in column D instead of in or out depending on which button is clicked.
Hi absent
First, you MUST use code tags around any code you post to a Thread. Click on Forum Rules...it describes how to do this.
Please post a dummy file so I can see what your worksheet looks like...are both buttons on the same row? In the same cell?
Regarding thisThe code is picking up the Text of the Button that's clicked. I just assumed the Buttons were labeled "IN" and "OUT".also the code that you wrote writes "Button 6" in column D instead of in or out depending on which button is clicked
So, show me what you have...perhaps I can help.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
My apologies jaslake,
the in code is...
and this is the out code ...Sub Check_IN_2() ' ' Check_IN Macro ' ' Range("$D2").Select ActiveCell.FormulaR1C1 = "IN" Range("E2").Select Selection.ClearContents End Sub
here is the requested sample, keep in mind it extends for about 100 rowsSub Check_out_2() ' ' Check_out Macro ' ' Range("$D2").Select ActiveCell.FormulaR1C1 = "OUT" Dim MYNUMBER MYNUMBER = InputBox("Please Enter Employee Number", "MY NUMBER INPUT BOX") Range("E2").Value = MYNUMBER End Sub
sample.jpg
yes the in and out buttons are in the same cell, it would be nice to be able to place the two buttons and then just copy them all the way through the 100 rows
Hi absent
No apologies necessary...don't want you to get hammered by a Moderator.
I really can't do much with a picture. Send me a copy of your workbook (with existing code). Eliminate (or change) proprietary information. If you're not willing to do so, I'll need to do it myself and I prefer to not guess.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Not a problem. Rows 1-20 have my existing code on it.
Hi absent
This code is in the attached for each Command Button in the worksheet and appears to do as you require. To make it easier for you to copy the Command Buttons to additional rows, click on the Office Button, click on Excel Options, click on Customize, in the Drop Down "Commands Not in Ribbon" select "Select Multiple Objects". This will allow you to copy the Command Buttons to additional rows (of course, you MUST DELETE the pre-existing Command Buttons before you copy the new ones). The same code applies to ALL command buttons. Let me know how you make out.
Option Explicit Sub test() Dim r As Range Dim eNumber As String Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell Select Case ActiveSheet.Buttons(Application.Caller).Characters.Text Case "OUT" eNumber = Application.InputBox _ (Prompt:="Please enter your Employee Number.", _ Title:="Employee Number", Type:=2) If eNumber = "" Then MsgBox "Please Enter Your Employee Number" Exit Sub Else Range(Cells(r.Row, 5), Cells(r.Row, 5)).Value = eNumber Range(Cells(r.Row, 4), Cells(r.Row, 4)).Value = ActiveSheet.Buttons(Application.Caller).Characters.Text End If Case "IN" Range(Cells(r.Row, 4), Cells(r.Row, 4)).Value = ActiveSheet.Buttons(Application.Caller).Characters.Text Range(Cells(r.Row, 5), Cells(r.Row, 5)).Value = "" End Select End Sub
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Great, that works really well! thank you very much. writing individual vba for each button was a very tedious task. thank you for making it easier. I have one more question though. would it be possible to easily add a confirmation box when clicking the in button, one that requires a yes or no responce and when you click no it terminates the script?
Hi Absent
Try this code...replace the underlined portion with your questionOption Explicit Sub test() Dim r As Range Dim eNumber As String Dim Answer As String Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell Select Case ActiveSheet.Buttons(Application.Caller).Characters.Text Case "OUT" eNumber = Application.InputBox _ (Prompt:="Please enter your Employee Number.", _ Title:="Employee Number", Type:=2) If eNumber = "" Then MsgBox "Please Enter Your Employee Number" Exit Sub Else Range(Cells(r.Row, 5), Cells(r.Row, 5)).Value = eNumber Range(Cells(r.Row, 4), Cells(r.Row, 4)).Value = ActiveSheet.Buttons(Application.Caller).Characters.Text End If Case "IN" Answer = MsgBox("Type your question here", vbYesNo, "Proceed?") If Answer = vbYes Then Range(Cells(r.Row, 4), Cells(r.Row, 4)).Value = ActiveSheet.Buttons(Application.Caller).Characters.Text Range(Cells(r.Row, 5), Cells(r.Row, 5)).Value = "" Else Exit Sub End If End Select End Sub
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
That is Great, i almost had it correct, i was missing the IF answer= thank you so much. one other thing that im missing in that im trying to have the cancel box in the employee number input box cancel the script from running when cancel is pressed. i know it an If statement that needs to be put in but but i keep getting Comile error: Variable not Defined. any suggestions?
Hi Absent
Try thisOption Explicit Sub test() Dim r As Range Dim eNumber As String Dim Answer As String Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell Select Case ActiveSheet.Buttons(Application.Caller).Characters.Text Case "OUT" TryAgain: eNumber = Application.InputBox _ (Prompt:="Please enter your Employee Number.", _ Title:="Employee Number", Type:=2) If eNumber = "False" Then Exit Sub If eNumber = "" Then MsgBox "Please Enter Your Employee Number" GoTo TryAgain Else Range(Cells(r.Row, 5), Cells(r.Row, 5)).Value = eNumber Range(Cells(r.Row, 4), Cells(r.Row, 4)).Value = ActiveSheet.Buttons(Application.Caller).Characters.Text End If Case "IN" Answer = MsgBox("Type your question here", vbYesNo, "Proceed?") If Answer = vbYes Then Range(Cells(r.Row, 4), Cells(r.Row, 4)).Value = ActiveSheet.Buttons(Application.Caller).Characters.Text Range(Cells(r.Row, 5), Cells(r.Row, 5)).Value = "" Else Exit Sub End If End Select End Sub
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
greta! thank you so much. It works!
Hi Absent
Happy I could help.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks