+ Reply to Thread
Results 1 to 3 of 3

VBA to optimize outflows

Hybrid View

  1. #1
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: VBA to optimize outflows

    Try:
    Sub test()
    Dim i As Long, j As Long
    Const startcolumn As Long = 4 ' starting with column D to allow changes in column C
    Const endcolumn As Long = 12 ' ending with column L
    Const maxallowedamount As Currency = 50000000
    i = startcolumn
    Do
      If Cells(27, i).Value <= maxallowedamount Then
        i = i + 1 'look at next column in row 27
      Else 'search for first value to change in row 24
        j = i - 1
        While Cells(24, j).Value = 0 And j >= startcolumn - 1
          j = j - 1
        Wend
        If j < startcolumn - 1 Then
          ' sorry no chance to correct
          MsgBox "Could not correct value in cell: " & Cells(27, i).Address(0, 0), vbCritical, "Giving up :-("
          i = endcolumn + 1
        ElseIf Cells(27, i).Value - maxallowedamount >= Cells(24, j).Value Then
          Cells(24, j).Value = 0
        Else
          Cells(24, j).Value = Cells(24, j).Value - (Cells(27, i).Value - maxallowedamount)
        End If
      End If
    Loop Until i > endcolumn
      
    End Sub
    Attached Files Attached Files
    Best Regards,

    Kaper

  2. #2
    Registered User
    Join Date
    08-28-2017
    Location
    Unknow
    MS-Off Ver
    2016
    Posts
    9

    Re: VBA to optimize outflows

    Thanks alot!

+ 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. Need Cumulative running totals that never fall below zero despite outflows
    By YukonSoDank in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-23-2019, 04:13 PM
  2. How can I optimize my code
    By viettest in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-08-2019, 05:02 PM
  3. [SOLVED] Optimize my VBA code
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-07-2019, 11:25 AM
  4. VBA to optimize your VBA possible?
    By alexgoaga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2017, 05:37 AM
  5. Optimize code
    By DarkKnightLupo in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-19-2014, 08:58 AM
  6. Replies: 2
    Last Post: 08-14-2013, 11:03 AM
  7. How to optimize
    By jonelamora in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 07-04-2012, 02:17 AM

Tags for this Thread

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