+ Reply to Thread
Results 1 to 5 of 5

How do I get the value of previous category?

Hybrid View

rheeyeonsang How do I get the value of... 12-11-2020, 07:20 PM
Ochimus Re: How do I get the value of... 12-11-2020, 10:01 PM
Gregb11 Re: How do I get the value of... 12-12-2020, 10:23 AM
rheeyeonsang Re: How do I get the value of... 12-14-2020, 12:31 PM
AliGW Re: How do I get the value of... 12-14-2020, 12:31 PM
  1. #1
    Registered User
    Join Date
    12-11-2020
    Location
    San Diego
    MS-Off Ver
    365
    Posts
    2

    Unhappy How do I get the value of previous category?

    Hello,

    I'm trying to get the value of a previous category for my personal finance sheet.
    I have different accounts and I want to have both old balance and new balance show that is maintained under the same table.
    1.png

    Bascially, I would need the current 'old balance' to show previous 'new balance' in the same 'account'.
    To simplify this question, here is an example.
    3.PNG

    As you can see, D7 shows C2.

    I was trying to use Index (New Balance Array, Row # of previous category).
    What I'm having trouble is getting the row# of the previous category.
    I was using COUNTIF (START OF CATEGORY : CURRENT CATEGORY, CATEGORY) to get the # of row that the previous category is within the category.
    Now, I am stuck on using this number to get the row number in overall.
    Attached Images Attached Images
    Last edited by rheeyeonsang; 12-14-2020 at 12:31 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,465

    Re: How do I get the value of previous category?

    rheeyeonsang,

    Macro in attached sample runs when you change any value cell (example assumes you put the value in Col D).
    It "undoes" the new price, copies and stores the old value, then reinstates the New Value.
    If the Old value and the New one are different, it pastes the "old" value into Col F of that row.
    If you change the Col D price again, the first change then becomes the "old" price in Col F, and so on.

    Option Explicit
    Dim f As Long, OldValue As Long
    Dim rng1 As Range
    'Dim OldValue As Variant
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        On Error GoTo ErrorHandler
        
        Set rng1 = Intersect(Target, Range("D2:D5"))
    
        If Target.Cells.Count > 1 Then Exit Sub
        
        If rng1 Is Nothing Then Exit Sub
        
        Application.EnableEvents = False
    
        Application.Undo
         
        OldValue = Target.Value
         
        Application.Undo
         
        Application.EnableEvents = True
         
             If OldValue <> Target.Value Then
             Target.Offset(0, 2) = OldValue
             End If
      
        
     
    ErrorHandler:
    
        Resume Next
        Application.EnableEvents = True
     
     End Sub
    Hope this helps

    Ochimus
    Attached Files Attached Files
    Last edited by Ochimus; 12-11-2020 at 10:08 PM.

  3. #3
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    3,182

    Re: How do I get the value of previous category?

    Since you're using O365, you can use the new XLOOKUP formula. Try this in cell D2 and copy down

    =XLOOKUP(B2,$B$1:$B1,$C$1:$C1,"N/A",0,-1)

    This gives you what you are showing under "What I want"

  4. #4
    Registered User
    Join Date
    12-11-2020
    Location
    San Diego
    MS-Off Ver
    365
    Posts
    2

    Re: How do I get the value of previous category?

    That's amazing.
    The xlookup function worked perfectly.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,404

    Re: How do I get the value of previous category?

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ 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. Replies: 1
    Last Post: 11-24-2020, 10:44 AM
  2. Chart - Category Label Disappears if the 1st Category not chosen
    By RebeccaD747 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-04-2019, 11:52 PM
  3. Replies: 0
    Last Post: 04-09-2014, 04:21 PM
  4. Filtering by text
    By saltarazan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-16-2013, 04:18 AM
  5. Replies: 2
    Last Post: 09-14-2012, 04:31 AM
  6. [SOLVED] Productsum: Highest Frequency Category, Specific Main Category, Frequency of Category
    By T86157 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-24-2012, 12:43 PM
  7. Single field fits fault category, event category determined by group of faults
    By SchoobsVT in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2010, 08:51 AM

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