+ Reply to Thread
Results 1 to 7 of 7

Worksheet needs certain cells to have a value before triggering the userform.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-25-2016
    Location
    Derby, England
    MS-Off Ver
    MS 2013
    Posts
    228

    Worksheet needs certain cells to have a value before triggering the userform.

    Hi,

    Please could someone help me?

    I have a worksheet (attached) and I would like certain cells to have values before triggering the userform.

    I have added the details to the worksheet with arrows which hopefully will make it easier to understand (I hope)

    Any help would be much appreciated.

    Kind Regards

    Dan
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Worksheet needs certain cells to have a value before triggering the userform.

    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Or Target.Row < 6 Or Target.Column <> 12 Then Exit Sub
    
    Application.EnableEvents = False
      
    On Error Resume Next
    Range(Cells(Target.Row, 3), Cells(Target.Row, 9)).SpecialCells(xlCellTypeBlanks).Select
    On Error GoTo 0
    
    If ActiveCell.Column <> 12 Then
    'Select Blank Cell
    Beep
    Else
    'No Blank Cell
    If Cells(Target.Row, 9) < 11 Or Cells(Target.Row, 11) <> "" Then
    UserForm1.Show
    Else
    Cells(Target.Row, 11).Select
    'Column K needs to be completed
    Beep
    End If
    End If
    
    Application.EnableEvents = True
      
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    10-25-2016
    Location
    Derby, England
    MS-Off Ver
    MS 2013
    Posts
    228

    Re: Worksheet needs certain cells to have a value before triggering the userform.

    Hi mehmetcik,

    thank you for your response but unfortunately its coming up with "Run Time Error 1004 - No cells were found

    and its highlighting this line:

    Range(Cells(Target.Row, 3), Cells(Target.Row, 9)).SpecialCells(xlCellTypeBlanks).Select
    Any ideas?

    Thanks again

    Dan

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Worksheet needs certain cells to have a value before triggering the userform.

    Try this:


    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Or Target.Row < 6 Or Target.Column <> 12 Then Exit Sub
    
    Application.EnableEvents = False
      
    On Error Resume Next
    Set Z = Range(Cells(Target.Row, 3), Cells(Target.Row, 9)).SpecialCells(xlCellTypeBlanks)
    On Error GoTo 0
    
    If Z.Column <> 12 Then
    'Select Blank Cell
    Beep
    Else
    'No Blank Cell
    If Cells(Target.Row, 9) < 11 Or Cells(Target.Row, 11) <> "" Then
    UserForm1.Show
    Else
    Cells(Target.Row, 11).Select
    'Column K needs to be completed
    Beep
    End If
    End If
    
    Application.EnableEvents = True
      
    End Sub

  5. #5
    Forum Contributor
    Join Date
    10-25-2016
    Location
    Derby, England
    MS-Off Ver
    MS 2013
    Posts
    228

    Re: Worksheet needs certain cells to have a value before triggering the userform.

    Hi mehmetcik,

    I've tried this code and it come up with a compile error - Variable not defined and it highlighted the Z =. So I put in Dim Z As Range, is that correct?

    but then it come up with the same error as before and highlighted the same line.

    Kind Regards

    Dan

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Worksheet needs certain cells to have a value before triggering the userform.

    I have modified it a bit and have done some testing.

    There is an error in your userform that you will need to address,

    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Or Target.Row < 7 Or Target.Column <> 12 Then Exit Sub
    
    Application.EnableEvents = False
      
    On Error Resume Next
    Z = Range(Cells(Target.Row, 3), Cells(Target.Row, 10)).SpecialCells(xlCellTypeBlanks).Column
    On Error GoTo 0
    
    If Z < 10 Then
    'Select Blank Cell
    Cells(Target.Row, Z).Select
    Beep
    Else
    'No Blank Cell
    If Cells(Target.Row, 9) < 11 Or Cells(Target.Row, 11) <> "" Then
    UserForm1.Show
    Else
    Cells(Target.Row, 11).Select
    'Column K needs to be completed
    Beep
    End If
    End If
    
    Application.EnableEvents = True
    
    End Sub
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    10-25-2016
    Location
    Derby, England
    MS-Off Ver
    MS 2013
    Posts
    228

    Re: Worksheet needs certain cells to have a value before triggering the userform.

    Hi mehmetcik,

    That's perfect mate, thank you. I've managed to sort the error in my userform as well.

    Thanks again

    Dan

+ 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. Triggering UserForm from Keyboard Shortcut
    By BeefNoodleSoup in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-18-2012, 03:11 AM
  2. Worksheet Change Event not triggering with cells containing formula
    By Skell in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-15-2012, 06:16 PM
  3. Cell Value Change triggering UserForm
    By danygiguere23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2012, 10:38 PM
  4. Stop code from triggering worksheet event
    By mashley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2010, 11:47 AM
  5. triggering a subroutine in one worksheet by changing cells in another
    By ronocnikral in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2009, 01:22 PM
  6. Triggering Worksheet Events
    By gnaiggg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-25-2007, 05:31 AM
  7. Userform combo box triggering macros
    By michaelberrier in forum Excel General
    Replies: 6
    Last Post: 06-10-2006, 08:30 AM
  8. [SOLVED] RTD value changes not triggering worksheet change event
    By DTM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2006, 12:10 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