question

cmccabe

Active Member
Joined
Feb 20, 2008
Messages
396
Is there a way in excel 2003 that a user can double click a cell and a user prompt asking to input data results? If I use code 1 I can use a macro it seems, but can it be modified so that a double click is required. Code 2 is what I thought of but it does not seem to work. Thanks.

Code 1
Code:
Sub Data ()
Cells(3, "A").Value = InputBox("Enter Case Number Between 1 and 50", "You must Enter a Value")
    Do While Cells(3, "A").Value < 1 Or Cells(3, "A").Value > 50
    Cells(3, "A").Value = InputBox("Enter a number Between 1 and 50", "Input Out of Range!")
    Loop
End Sub

Code 2 (HSCBM is the workshhet name)
Code:
Private Sub HSCBM_RD_BeforeDoubleClick_()
    Cells(3, "A").Value = InputBox("Enter Case Number Between 1 and 50", "You must Enter a Value")
    Do While Cells(3, "A").Value < 1 Or Cells(3, "A").Value > 50
    Cells(3, "A").Value = InputBox("Enter a number Between 1 and 50", "Input Out of Range!")
    Loop
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Cells(3, "A").Value = InputBox("Enter Case Number Between 1 and 50", "You must Enter a Value")
Do While Cells(3, "A").Value < 1 Or Cells(3, "A").Value > 50
    Cells(3, "A").Value = InputBox("Enter a number Between 1 and 50", "Input Out of Range!")
Loop
End Sub
 
Upvote 0
That works prefectly. Is there a way to use that command to a range of cells? Instead of only using A3 use a range of A3 to A53? Thanks.
 
Upvote 0
Try this

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A3:A53")) Is Nothing Then Exit Sub
Cancel = True
Target.Value = InputBox("Enter Case Number Between 1 and 50", "You must Enter a Value")
Do While Target.Value < 1 Or Target.Value > 50
    Target.Value = InputBox("Enter a number Between 1 and 50", "Input Out of Range!")
Loop
End Sub
 
Upvote 0
One last ?...

The last two data inputs are text:
Code 1 restricts the entry to a number, can that be modified to restrict the entry to text? Thanks.

Code 1
Code:
Cells(3, "E").Value = InputBox("Enter Age", "You must Enter a Value")
    [U]Do While Cells(3, "E").Value < 1 Or Cells(3, "E").Value > 150
[/U]    Cells(3, "E").Value = InputBox("Enter a number Between 1 and 150", "Input Out of Range!")
Loop
 
Upvote 0
Maybe like this

Code:
Cells(3, "E").Value = InputBox("Enter Description", "You must Enter Text")
Do While IsNumeric(Cells(3, "E").Value) Or Cells(3, "E").Value = ""
    Cells(3, "E").Value = InputBox("Enter Description", "Error!")
Loop
 
Upvote 0
Sorry, this is it hopefully.

When code 1 is used the user is asked for Case Number and then an Age. However when I go to the next row Case Number is entered on the next row but Age over-writes E3.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Is there a way that when A moves down a row so can E. They are both the same range A3:A53 and E3:E53. Thanks.

Code 1:
Code:
[FONT=Times New Roman][SIZE=3]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)[/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]    If Intersect(Target, Range("A3:A53")) Is Nothing Then Exit Sub[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Cancel = True[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Target.Value = InputBox("Enter Case Number Between 1 and 50", "You must Enter a Value")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Do While Target.Value < 1 Or Target.Value > 50[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Target.Value = InputBox("Enter a number Between 1 and 50", "Input Out of Range!")[/FONT][/SIZE]
<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on">[FONT=Times New Roman][SIZE=3]Loop[/SIZE][/FONT]</st1:place>
[SIZE=3][FONT=Times New Roman]   Cells(3, "E").Value = InputBox("Enter Age", "You must Enter a Value")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]   Do While Cells(3, "E").Value < 1 Or Cells(3, "E").Value > 150[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]   Cells(3, "E").Value = InputBox("Enter a number Between 1 and 150", "Input Out of Range!")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman] <st1:place w:st="on">Loop</st1:place>[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3]End Sub[/SIZE][/FONT]
 
Upvote 0
If column A is meant to be numeric and column E is meant to be text, try like this

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A3:A53,E3:E53")) Is Nothing Then Exit Sub
Cancel = True
Select Case Target.Column
    Case 1
        Target.Value = InputBox("Enter Case Number Between 1 and 50", "You must Enter a Value")
        Do While Target.Value < 1 Or Target.Value > 50
            Target.Value = InputBox("Enter a number Between 1 and 50", "Input Out of Range!")
        Loop
    Case 5
        Target.Value = InputBox("Enter Description", "You must Enter Text")
        Do While IsNumeric(Target.Value) Or Target.Value = ""
            Target.Value = InputBox("Enter Description", "Error!")
        Loop
End Select
End Sub
 
Upvote 0
The code works.

Code 1 is the final code:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A3:A53,E3:E53,M3:M53,O3:O53")) Is Nothing Then Exit Sub
Cancel = True
Select Case Target.Column
    Case 1
        Target.Value = InputBox("Enter Case Number Between 1 and 50", "You must Enter a Value")
        Do While Target.Value < 1 Or Target.Value > 50
            Target.Value = InputBox("Enter a number Between 1 and 50", "Input Out of Range!")
        Loop
    Case 5
        Target.Value = InputBox("Enter Age", "You must Enter a Value")
        Do While Target.Value < 1 Or Target.Value > 150
            Target.Value = InputBox("Enter a number Between 1 and 150", "Input Out of Range!")
    Case 13
        Target.Value = InputBox("Enter Donor", "You must Enter Text")
        Do While IsNumeric(Target.Value) Or Target.Value = ""
            Target.Value = InputBox("Enter Donor", "Error!")
        Loop
     Case 15
        Target.Value = InputBox("Enter Description", "You must Enter Text")
        Do While IsNumeric(Target.Value) Or Target.Value = ""
            Target.Value = InputBox("Enter Description", "Error!")
        Loop
End Select
End Sub

However when I enter this I get a SELECT Case error and Case 13 and 15 are highlighted. Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top