+ Reply to Thread
Results 1 to 12 of 12

Add a dialogue box

Hybrid View

nkitchen31 Add a dialogue box 01-16-2017, 03:29 AM
nkitchen31 Re: Add a dialogue box 01-16-2017, 03:37 AM
mikerickson Re: Add a dialogue box 01-16-2017, 03:45 AM
nkitchen31 Re: Add a dialogue box 01-16-2017, 08:16 AM
nkitchen31 Re: Add a dialogue box 01-16-2017, 08:24 AM
nkitchen31 Re: Add a dialogue box 01-16-2017, 05:56 PM
Logit Re: Add a dialogue box 01-16-2017, 06:07 PM
nkitchen31 Re: Add a dialogue box 01-16-2017, 06:12 PM
Logit Re: Add a dialogue box 01-16-2017, 06:18 PM
Logit Re: Add a dialogue box 01-16-2017, 06:36 PM
nkitchen31 Re: Add a dialogue box 01-16-2017, 07:52 PM
Logit Re: Add a dialogue box 01-16-2017, 10:20 PM
  1. #1
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Add a dialogue box

    If a cell has a value in it, I would like have a box come up and ask for a value (number). There are a possibility of 15 cells. And I want a different cell to add up all the times that I put in the dialog box.

    Thanks in advance!

  2. #2
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: Add a dialogue box

    Like if any of the cells between F5:F20 have an "x" then it'll ask how much time. And it'll keep track of all the times entered and add them up in A5.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Add a dialogue box

    First put =SUM(F5:F20) in A5


    Then this Sub could be run to get your values.

    Sub Test()
        Dim oneCell as Range
    
        For Each oneCell in Range("F5:F20")
            If LCase(oneCell.Value) = "x" Then
                oneCell.Value = Application.InputBox("Enter time")
    
                If oneCell.Value = False Then
                    Rem Cancel pressed
                    oneCell.Value = "x"
                    Exit Sub
                End If
            End If
        Next oneCell
    
    End Sub
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: Add a dialogue box

    I did that in the Visual Basic editor... and nothing happens when I put an "x" in those columns...

  5. #5
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: Add a dialogue box

    Here is a screenshot. Thanks for your help.

    Screen Shot 2017-01-16 at 4.22.00 AM.png

  6. #6
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: Add a dialogue box

    Perhaps there is a different way to do this? B4 needs to be added up automatically, all the times that are entered in the "Enter Credit" if there is an "x" in the I column.

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Add a dialogue box

    Did you add a CommandButton attached to the macro "Sub Test() so when clicked it will fire the macro ?

  8. #8
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: Add a dialogue box

    Negative ... I haven't done VB since high school bak in the late 90's ... I don't remember much haha. But is there a different way to do this besides VB and having to add in extra steps? Thank you.

  9. #9
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Add a dialogue box

    You could place the macro in the Sheet Change event.

    Both of these look the same but they are not. Closely look at the Sub name at the top of each. This goes in the VBE editor window for the affected worksheet.
    In your pic you have Sheet3(Feb) highlighted. If you click on that, as you did to insert the first version of the macro, delete the existing macro, then paste
    one of these in its place.

    You only need to paste one of the macros. I would start with the second one.


    # 1

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim oneCell As Range
        
            For Each oneCell In Range("F5:F20")
                If LCase(oneCell.Value) = "x" Then
                    oneCell.Value = Application.InputBox("Enter time")
        
                    If oneCell.Value = False Then
                        Rem Cancel pressed
                        oneCell.Value = "x"
                        Exit Sub
                    End If
                End If
            Next oneCell
    End Sub

    # 2

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim oneCell As Range
        
            For Each oneCell In Range("F5:F20")
                If LCase(oneCell.Value) = "x" Then
                    oneCell.Value = Application.InputBox("Enter time")
        
                    If oneCell.Value = False Then
                        Rem Cancel pressed
                        oneCell.Value = "x"
                        Exit Sub
                    End If
                End If
            Next oneCell
    End Sub

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Add a dialogue box

    I've tried the two new macros. Neither one works satisfactorily.

    Try this :

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Intersect(Target, Range("F5:F20")).Value = "x" Then
            MsgBox "Enter Time Value Only ! ", vbOKOnly & vbCritical, "Wrong Data Entry"
            Intersect(Target, Range("F5:F20")).Select
    End If
    
    End Sub
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: Add a dialogue box

    I will check it when I get to my computer. Thank you.

    But the value of the cells should still be "x", but the sum of B5 should be all the values that were entered into the "Enter Credit" msgBox ... make sense?

    Thanks again!

  12. #12
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Add a dialogue box

    .
    Add this formula to the Formula Bar for cell B5:
    =SUM(F5:F20)
    Change the macro code to this:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    ''<---- Two new lines of code --->
    If Intersect(Target, Range("F5:F20")) Is Nothing Then Exit Sub
    If Intersect(Target, Range("F5:F20")) = "" Then Exit Sub
    ''<--- Two new lines of code --->
    
    If Intersect(Target, Range("F5:F20")).Value = "x" Then
            MsgBox "Enter Time Value Only ! ", vbOKOnly & vbCritical, "Wrong Data Entry"
            Intersect(Target, Range("F5:F20")).Select
    End If
    
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dialogue Box VBA
    By KG23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-15-2014, 01:27 PM
  2. Pop up dialogue box
    By TG77 in forum Excel General
    Replies: 1
    Last Post: 06-28-2010, 11:15 AM
  3. Dialogue Box?
    By sgilleland in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2007, 04:39 AM
  4. dialogue pop up
    By Micayla Bergen in forum Excel General
    Replies: 5
    Last Post: 06-23-2006, 05:50 PM
  5. pop up dialogue box
    By Micayla Bergen in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-22-2006, 09:40 PM
  6. pop up dialogue
    By Micayla Bergen in forum Excel General
    Replies: 0
    Last Post: 06-22-2006, 09:25 PM
  7. SaveAs Dialogue Box
    By Tony D in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2006, 05:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1