?
Solved

Navigating with macros on a existing Workbook

Posted on 2011-09-22
8
Medium Priority
?
287 Views
Last Modified: 2012-05-12
EE Professionals,

EE has helped me develop a neat little App. for scheduling tasks and assigning roles/responsibilities.  I'm having some challenges with "navigation" - When you put in a priority, the app. automatically changes the order/priority. The updating for the chart is automatic when you put in new data in the ajointing cells.  

What I'd like to see is that you can put in all the data on a row and the information is updated either when the priority is set (Col. A) or when the Role is assigned (Col. E).  Also, the cursor needs to move to the next cell rather then reset to a particular cell.

Any improvement would be much appreciated.

Thank you,

B.
RASCI-Sheetv5.xlsm
0
Comment
Question by:Bright01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 5

Expert Comment

by:slycoder
ID: 36582065
I'm working on a fix - but a simple way would be to have a flag for "AutoUpdate" I put one in E2.  This can be tied to a Form Control Checkbox.

Hope this helps.


Copy-of-RASCI-Sheetv5.xlsm
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36582108
Easier than I thought - just wrap your Worksheet_Change code with:

        If ActiveCell.Column = 1 Or ActiveCell.Column = 5 Then
            ...
        End if

Feel free to remove the other wrapper if you do not want the Checkbox:
       If (UCase(Trim(Range("E2").Value)) = "TRUE") Then
        ...
       End if

Thanks

Copy-of-RASCI-Sheetv5.xlsm
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36582694
>> Also, the cursor needs to move to the next cell rather then reset to a particular cell.

This is fixed by adding a "memory" cell regarding the activecell rather than the target

    Dim myCurrentCell As String
    myCurrentCell = ActiveCell.Address


and referencing myCurrentCell in place of:

            'Target.Select

            Range(myCurrentCell).Select

Hope this covers all the bases


Copy-of-RASCI-Sheetv5.xlsm
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Bright01
ID: 36582872
slycoder,

This looks great!  Two small things here, is there a way that when you put a priority in a cell in col. A, that it won't flicker and that it will put the cursor into the blank cell that has opened up?  So if I put in 7.5, and it opens up another row, the cursor will be in cell B next to 7.5?

Also, what considerations should I have if I want to move around either the input area or the chart?  I don't need specifics, just a few sentences of caution or do this......

Much thanks, again, looks great.

B.
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36583124
I'll stop posting the full spreadsheet (unless requested).

Change the Worksheet_Change function to have the following:

 
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim myCurrentCell As String
    myCurrentCell = ActiveCell.Address
    
    If (UCase(Trim(Range("E2").Value)) = "TRUE") Then
    
        If Target.Column = 1 Or Target.Column = 5 Then
        
            Application.ScreenUpdating = False
        
            Dim LastR As Long
            
            With Me
                LastR = .Cells(.Rows.Count, "a").End(xlUp).Row
                If Not Intersect(Me.Range("a12:a" & LastR), Target) Is Nothing Then
                    With Application
                        .EnableEvents = False
                        .ScreenUpdating = False
                    End With
                    With .Sort
                        .SortFields.Clear
                        .SortFields.Add Key:=Range("A12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                        .SortFields.Add Key:=Range("B12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                        .SortFields.Add Key:=Range("C12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                        .SortFields.Add Key:=Range("D12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                        .SortFields.Add Key:=Range("E12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                            
                            
                        .SetRange Range("A12:E" & LastR)
                        .Header = xlYes
                        .MatchCase = False
                        .Orientation = xlTopToBottom
                        .SortMethod = xlPinYin
                        .Apply
                    End With
                    With Application
                        .EnableEvents = True
                        .ScreenUpdating = True
                        End With
                End If
            End With
            PopulateRasciTable
            'Target.Select
            Range(myCurrentCell).Select
            
            If Target.Column = 1 And ActiveCell.Column = 2 Then
           '     ActiveCell.Offset(-1, 0).Select
            Debug.Print ActiveCell.Value, ActiveCell.Address
                Do While ActiveCell.Value <> ""
                    ActiveCell.Offset(-1, 0).Select
                Loop
            End If
    
            Application.ScreenUpdating = True
            
        End If
    
    End If

End Sub

Open in new window


Glad to hear it's what you need.

Thanks
0
 
LVL 5

Accepted Solution

by:
slycoder earned 2000 total points
ID: 36583174
Bug Fix - when you you change the priority - it runs to the top of the list.

use this one instead:


 
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim myCurrentCell As String
    Dim myAllowFindEmptyCell As Boolean
    myCurrentCell = ActiveCell.Address
    myAllowFindEmptyCell = False
    
    If (UCase(Trim(Range("E2").Value)) = "TRUE") Then
    
        If Target.Column = 1 Or Target.Column = 5 Then
        
            If Target.Offset(1, 0) = "" Then
                myAllowFindEmptyCell = True
            End If
            
            Application.ScreenUpdating = False
        
            Dim LastR As Long
            
            With Me
                LastR = .Cells(.Rows.Count, "a").End(xlUp).Row
                If Not Intersect(Me.Range("a12:a" & LastR), Target) Is Nothing Then
                    With Application
                        .EnableEvents = False
                        .ScreenUpdating = False
                    End With
                    With .Sort
                        .SortFields.Clear
                        .SortFields.Add Key:=Range("A12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                        .SortFields.Add Key:=Range("B12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                        .SortFields.Add Key:=Range("C12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                        .SortFields.Add Key:=Range("D12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                        .SortFields.Add Key:=Range("E12"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                            DataOption:=xlSortNormal
                            
                            
                        .SetRange Range("A12:E" & LastR)
                        .Header = xlYes
                        .MatchCase = False
                        .Orientation = xlTopToBottom
                        .SortMethod = xlPinYin
                        .Apply
                    End With
                    With Application
                        .EnableEvents = True
                        .ScreenUpdating = True
                        End With
                End If
            End With
            PopulateRasciTable
            'Target.Select
            Range(myCurrentCell).Select
            
            If (Target.Column = 1 And ActiveCell.Column = 2) And myAllowFindEmptyCell = True Then
                Debug.Print ActiveCell.Value, ActiveCell.Address
                Do While ActiveCell.Value <> ""
                    ActiveCell.Offset(-1, 0).Select
                Loop
            End If
    
            Application.ScreenUpdating = True
            
        End If
    
    End If

End Sub

Open in new window


This little bit of code is a "hack" to say - if the new position is in column 2 (from column 1) - then keep going up until there is an empty spot - Only if this was added as a new item.

Thanks.
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36583241
>>> what considerations should I have ...

I'm not sure - basically work with the users that will be doing the data entry and see how they work, what pitfalls they come across and what ideas they have.

I've learned - it's hard to make programs fool-proof because fools are so ingenious!

0
 

Author Closing Comment

by:Bright01
ID: 36583419
Much thanks!  Great coding.

B.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question