Consulting

Results 1 to 10 of 10

Thread: Solved: Amend Macro in worksheet Cashflow Yearly

  1. #1
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location

    Solved: Amend Macro in worksheet Cashflow Yearly

    Need to slightly re design the following workbook......

    1. Amend VBA Code worksheet "Cashflow Yearly"....

    need to the macro to remain the same OTHER than remove the part of generating the same forumla in each section i.e. see hightlighted....in yellow as to worksheet "Cashflow Q4".....

    so that know when the macro is run the formula in cell F6 is = CashFlow Q4$F$6
    and NOT that longer array formula currently in there at the moment...........

    Looking at way to simplify the workbook.........

  2. #2
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    attached workbook

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That formula is not an array formula even thoough you have array-entered it.

    All the formulae return an error as linked to another workbook.

    The code you supply dosen't generate that formula.

    So the question was again ...?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    cell F6 is = CashFlow Q4$F$6 in worksheet Cashflow Yearly.......and no long complicated formulas in worksheet "cashflows Yearly".....

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    ??????????
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    ok here is the code apologies for the confusion

    [VBA]
    Sub alaeod_6() 'Add Line At End Of Data
    Dim str1 As String
    Dim lastrow As Long
    Dim rng As Range
    Dim startrow As Long
    Dim strData As String
    Dim sup As String
    Dim dem As String

    str1 = "B"
    With Sheets("CashFlow Yearly")
    lastrow = .Cells(.Cells.Rows.Count, str1).End(xlUp).Row
    strData = .Cells(lastrow, str1).Value
    For startrow = lastrow - 1 To 1 Step -1
    sup = .Cells(startrow + 1, "B").Value
    sup = Replace(sup, "+", "_plus")
    sup = Replace(sup, ", ", "~")
    sup = Replace(sup, " ", "_")
    sup = Replace(sup, "~", ", ")
    sup = Replace(sup, "-", "_")
    sup = Replace(sup, "/", "_")
    sup = Replace(sup, "(", "")
    sup = Replace(sup, ")", "")
    dem = .Cells(startrow + 1, "C").Value
    dem = Replace(dem, "+", "_plus")
    dem = Replace(dem, ", ", "~")
    dem = Replace(dem, " ", "_")
    dem = Replace(dem, "~", ", ")
    dem = Replace(dem, "-", "_")
    dem = Replace(dem, "/", "_")
    dem = Replace(dem, "(", "")
    dem = Replace(dem, ")", "")
    .Cells(startrow + 1, "E") = "CF_" & sup & "_" & dem
    .Cells(startrow + 1, "F").Resize(1, 48).FormulaArray = _
    "=(Vol_" & sup & "_" & dem & _
    " * " & "Price_" & dem & "_" & sup & ") - (" & _
    "Vol_" & sup & "_" & dem & " * (" & _
    "Price_" & sup & "_" & dem & " + " & _
    "UFC_" & sup & "_" & dem & "))"
    Range(.Cells(startrow, str1), .Cells(startrow, "BA")).NumberFormat = "#,##0.00_ ;-#,##0.00;-"
    If .Cells(startrow, str1).Value <> strData Then
    startrow = startrow + 1
    Exit For
    End If
    Next
    Set rng = Range(.Cells(startrow, str1), .Cells(lastrow, "BA"))
    rng.NumberFormat = "#,##0.00_ ;-#,##0.00;-"
    End With

    With rng.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
    End With
    With rng.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
    End With
    With rng.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
    End With

    With Sheets("CashFlow Yearly")
    Set rng = Range(.Cells(startrow, str1), .Cells(lastrow, "F"))

    With rng.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    End With

    End Sub
    [/VBA]

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Lets start this conversation once again Pete, by clearly stating what it is you are chasing (step by step) and what it is that you want the data to look like.

    Until you do that most people are simply going to step around your thread.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by Aussiebear
    Lets start this conversation once again Pete, by clearly stating what it is you are chasing (step by step) and what it is that you want the data to look like.

    Until you do that most people are simply going to step around your thread.
    Agreed,
    I've read post #1 three times now, and have no idea what is required.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    Solved it.....might have taken 8 hours

    [VBA] Sub alaeod_6() 'Add Line At End Of Data
    Dim str1 As String
    Dim lastrow As Long
    Dim rng As Range
    Dim startrow As Long
    Dim strData As String
    Dim sup As String
    Dim dem As String

    str1 = "B"
    With Sheets("CashFlow Yearly")
    lastrow = .Cells(.Cells.Rows.Count, str1).End(xlUp).Row
    strData = .Cells(lastrow, str1).Value
    For startrow = lastrow - 1 To 1 Step -1
    sup = .Cells(startrow + 1, "B").Value
    sup = Replace(sup, "+", "_plus")
    sup = Replace(sup, ", ", "~")
    sup = Replace(sup, " ", "_")
    sup = Replace(sup, "~", ", ")
    sup = Replace(sup, "-", "_")
    sup = Replace(sup, "/", "_")
    sup = Replace(sup, "(", "")
    sup = Replace(sup, ")", "")
    dem = .Cells(startrow + 1, "C").Value
    dem = Replace(dem, "+", "_plus")
    dem = Replace(dem, ", ", "~")
    dem = Replace(dem, " ", "_")
    dem = Replace(dem, "~", ", ")
    dem = Replace(dem, "-", "_")
    dem = Replace(dem, "/", "_")
    dem = Replace(dem, "(", "")
    dem = Replace(dem, ")", "")
    .Cells(startrow + 1, "E") = "CF_" & sup & "_" & dem
    .Cells(startrow + 1, "F").Resize(1, 48).FormulaArray = _
    "=if(iserror((Revenue_" & dem & "_" & sup & _
    " - " & "Purchase_" & sup & "_" & dem & ")),0," & _
    "(Revenue_" & dem & "_" & sup & _
    " - " & "Purchase_" & sup & "_" & dem & "))"

    Range(.Cells(startrow, str1), .Cells(startrow, "BA")).NumberFormat = "#,##0.00_ ;-#,##0.00;-"
    If .Cells(startrow, str1).Value <> strData Then
    startrow = startrow + 1
    Exit For
    End If
    Next
    Set rng = Range(.Cells(startrow, str1), .Cells(lastrow, "BA"))
    rng.NumberFormat = "#,##0.00_ ;-#,##0.00;-"
    End With

    With rng.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
    End With
    With rng.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
    End With
    With rng.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
    End With

    With Sheets("CashFlow Yearly")
    Set rng = Range(.Cells(startrow, str1), .Cells(lastrow, "F"))

    With rng.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    End With

    End Sub[/VBA]

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Pete, Great to see you have been able to provide the solution, however if you post code to this forum would you please use the VBA tags option, as this makes the code a whole lot easier to read. OK?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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