Consulting

Page 1 of 4 1 2 3 ... LastLast
Results 1 to 20 of 79

Thread: Creating a single Table with different formulas Excel VBA

  1. #1

    Exclamation Creating a single Table with different formulas Excel VBA

    Hi everyone! I just signed up today to ask for help from y'all. I am a newbie when it comes to VBA. I am literally new like I started just yesterday, y'know. Basically I am trying to create a single table with multiple formulas in it. I can't manually put the formulas because the list in the database sheet is dynamic.

    What I am trying to do is this:

    a.jpg

    Categories can be found on the database sheet. Number format of sub categories depend on their respective formats which are indicated on the other sheets.

    This is what I have so far: I got this idea from one of the threads here:

    Sub testing()
    
    Set Rng = Sheets("Database").Range("A1").CurrentRegion
    Set Rng = Intersect(Rng, Rng.Offset(1))
    MCategory = ""
    
    
    For Each cll In Rng.Cells
        MCategory = cll.Value
     
      Set Destn = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1)
      With Destn
        .Value = cll.Offset(, 1).Value
      End With
    Next cll
    End Sub


    I am only able to do the categories part, but I don't know how to do the formulas since they differ depending on whether it's for monthly/weekly and Main Category/Sub Category.

    I am using Windows 10 and Office 365 if that's something you need to know.

    Attached herewith is my sample file.

    Your gracious help is highly appreciated. Thank you so much

    PS: I also posted here at 1:51AM today:
    https://www.mrexcel.com/board/thread...l-vba.1131940/
    Attached Files Attached Files

  2. #2
    Hmm any help is super appreciated.

  3. #3
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Hi and welcome to the forum.

    I think you need to explain yourself better... or at least say what you want with an example!
    Semper in excretia sumus; solum profundum variat.

  4. #4
    HI Paul thank you for replying.

    I have a sheet called Database. It contains all information about categories and sub categories like their target numbers per sub category, as well as the format of each target (like if they are in decimal or percentage). This list changes a lot.

    In my Table sheet, I need to list each category with their sub categories below them. Then I need to compute their values based on the weekly and monthly sheet. However, the main category rows have different formulae versus the sub category rows. They also differ on the number format.

  5. #5
    Hi everyone! Maybe another one also has an idea like paulked?

    Any help is truly appreciated! Thank you!

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Some suggested Procedures (examples only)

    Sub CellFormat (cll As Range, FormatType As String)
       If LCase(FormatType) = "percentage" then Cll.Numberforemat = ...
       If LCase(FormatType) =  "decimal" then Cll.Numberforemat = ...
       If LCase(FormatType) =  "bold" then Cll.Font = ...
       'Room to add more conditions if/when needed
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    Hi Sam thanks for responding
    I am actually more concerned about the formulae part because they are a lot and they differ for categories and sub categories and whether they are for weekly or monthly --- and they are all in a single table.

    I was thinking if this is possible using calculated fields in a Pivot? Is it?

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Excel Cell Fomulas are Strings in VBA.
    Precede the formula with an apostrophe in the cell and it becomes a String an not a Formula '=SumIf(blahblah). Put those in Column B and in Column A place the names/uses of the formula Cat1SubCat1Wkly then you can use the same method as above.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    Hi Sam. My apologies, that got me confused ��
    I am literally new to all this, I literally started like a day before posting here so I really have no idea about what you're talking about ��

    Would you mind giving me a rough example?
    Does this require loops? Or something?

  10. #10
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  11. #11
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    If you create a pivottable based on the data in sheet weekly, no VBA is needed.

  12. #12
    VBAX Tutor
    Joined
    Jan 2020
    Posts
    204
    Location

    Question Calculated Fields Pivot Tables

    I understand that calculated fields only apply to columns in a Pivot Table, but is there a way to do as well for rows? Like the main category has a different formula then the sub category also has a different formula. However the sub categories are placed under each main category. They are not on 2 separate columns

    Attached is my sample workbook.

    I have this formula on Table Sheet:

    =IFS(
    
    AND(LEFT(F$6,3)="MTD",(COUNTIF('Sheet2'!$W:$W,Table!$B8))=1), IFERROR(COUNTIFS(Monthly!$L:$L,"P",Monthly!$J:$J,Table!F$7,Monthly!$A:$A,Table!$B8)/SUMIFS(Monthly!$M:$M,Monthly!$J:$J,Table!F$7,Monthly!$A:$A,Table!$B8),"-"),
    
    
    AND(LEFT(F$6,3)="MTD",(COUNTIF('Sheet2'!$W:$W,Table!$B8))=0,$D8="Percentage"), TEXT(SUMIFS(Monthly!$K:$K,Monthly!$J:$J,Table!F$7,Monthly!$A:$A,Table!$B$8,Monthly!$D:$D,Table!$B8),"0.00%"),
    AND(LEFT(F$6,3)="MTD",(COUNTIF('Sheet2'!$W:$W,Table!$B8))=0,$D8="Decimal"), TEXT(SUMIFS(Monthly!$K:$K,Monthly!$J:$J,Table!F$7,Monthly!$A:$A,Table!$B$8,Monthly!$D:$D,Table!$B8),"0.00 "),
    
    
    AND(LEFT(F$6,3)="WEE",(COUNTIF('Sheet2'!$W:$W,Table!$B8))=1), IFERROR(COUNTIFS(Weekly!$L:$L,"P",Weekly!$J:$J,Table!F$7,Weekly!$A:$A,Table!$B8)/SUMIFS(Weekly!$M:$M,Weekly!$J:$J,Table!F$7,Weekly!$A:$A,Table!$B8),"-"),
    
    
    AND(LEFT(F$6,3)="WEE",(COUNTIF('Sheet2'!$W:$W,Table!$B8))=0,$D8="Percentage"), TEXT(SUMIFS(Weekly!$K:$K,Weekly!$J:$J,Table!F$7,Weekly!$A:$A,Table!$B$8,Weekly!$D:$D,Table!$B8),"0.00%"),
    AND(LEFT(F$6,3)="WEE",(COUNTIF('Sheet2'!$W:$W,Table!$B8))=0,$D8="Decimal"), TEXT(SUMIFS(Weekly!$K:$K,Weekly!$J:$J,Table!F$7,Weekly!$A:$A,Table!$B$8,Weekly!$D:$D,Table!$B8),"0.00 ")
    )
    It works only for the first main category and sub categories but if I move on to the new main category it fails already.
    Attached Files Attached Files
    Last edited by jazz2409; 04-28-2020 at 09:49 PM.

  13. #13
    Hello, my project partner Jazz Homer posted a new thread regarding this. I think she was able to explain this better than I did.

  14. #14
    Quote Originally Posted by snb View Post
    If you create a pivottable based on the data in sheet weekly, no VBA is needed.
    The thing about Pivots is that while we can create calculated fields, it will be a stand alone field instead of being values using existing data as columns

  15. #15
    Hello, if there's anyone who can help me and my project partner Jazz Homer. Please. Thank you.

    I also posted Jazz's post here: https://superuser.com/questions/1546...s-pivot-tables

  16. #16
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I think your data structure is completely FuBar and needs to be completely rebuilt from scratch.

    I looks to me as if you are trying to save (no cost) Real Estate by consolidating as much information for Users as possible on as few Excel Worksheets as possible.

    I have attached a sample of a well designed, at least IMO, data Table. Note that the Workbook Name contains the Year it is to be used in. I did break one rule of data tables in that I included both Monthly and Weekly data tables on one sheet.
    Attached Files Attached Files
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  17. #17
    VBAX Tutor
    Joined
    Jan 2020
    Posts
    204
    Location
    Sorry what is FuBar?
    This is what they gave us to use.. But I am willing to change it if it's going to make things better (which I think it will)

    Actually yes it's for a real estate company 🤣

  18. #18
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    I'd Google Fubar rather than ask for an answer here
    Semper in excretia sumus; solum profundum variat.

  19. #19
    VBAX Tutor
    Joined
    Jan 2020
    Posts
    204
    Location
    Sorry but is there any chance that I can still continue with my sample workbook? I already asked if they are willing to change the view but they are not

    They really want the sub categories be under each main category and both have different formulae like the one I indicated above Also they want both MTD and 8-week view just like that

    Initially they just wanted to include main categories in that table but suddenly they wanted the sub categories be included under each main category and then look up the value from the two sheets

  20. #20
    VBAX Tutor
    Joined
    Jan 2020
    Posts
    204
    Location
    Quote Originally Posted by paulked View Post
    I'd Google Fubar rather than ask for an answer here
    I just did.. It's my first time to encounter such term

Tags for this Thread

Posting Permissions

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