Results 1 to 2 of 2

Reducing over many cells

Threaded View

  1. #1
    Registered User
    Join Date
    08-25-2017
    Location
    Cologne, Germany
    MS-Off Ver
    2010
    Posts
    1

    Reducing over many cells

    Hi,

    I have a problem with my code. Maybe somebody can help me.

    I have 9 worksheets for every department of my company.
    Every department has an own overtime sheet, the overtime is sorted by month and worker (Worker 1´s overtime is starting E5 (overtime 2016) to R5 (december 2017)).

    The foremen writes freetime in Column "D". This freetime reduces the overtime (starting with E5). If e5 ist "0", the rest of the freetime reduces "F5" etc.

    Example:
    Worker 1 has 400 hours overtime in 2016, 20 in january 2017, 32 in february 2017....
    foreman 2 writes 60 hours reducing freetime in "D5" = 340 hours overtime in 2016 for worker 1.
    Worker 3 has 20 hours overtime in 2016, 20 hours in january 2017. etc.
    Foreman 4 writes 30 hours reducing freetime in "d6" = 0 hours overtime left in 2016, 10 left in january 2017, etc.
    Column "d" is emty after complete reduced.

    My code has an error. It does not work.
    Can you tell me where?
    Thanks for your help.
    Ben
    Sub ReCalcOvertime()
    Dim rng As Range
    Dim rngAbgbH As Range, rngMon As Range
    Dim iMon As Integer
    
    For Each rng In Usedrange.Rows
    Set rngAbgbH = rng.Cells(4, 4) ' reduced overtime
    If IsNumeric(rngAbgbH) Then
    For iMon = 4 To 18
    Set rngMon = rng.Cells(4, 4 + iMon)
    If rngAbgbH.Value >= rngMon.Value Then
    rngAbgbH.Value = rngAbgbH.Value - rngMon.Value
    rngMon.Value = 0
    Else
    rngMon.Value = rngMon.Value - rngAbgbH.Value
    rngAbgbH.Value = 0
    End If
    If rngMon.Value = 0 Then
    rngMon.ClearContents
    End If
    If rngAbgbH.Value = 0 Then
    rngAbgbH.ClearContents
    Exit For
    End If
    Next
    End If
    Next
    End Sub
    Last edited by alansidman; 08-25-2017 at 09:02 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Reducing of materials
    By Coach86 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-30-2016, 12:56 AM
  2. Reducing 4 functions to 1
    By MattRNR in forum Excel General
    Replies: 0
    Last Post: 10-15-2014, 11:16 PM
  3. Reducing fractions
    By blackshag in forum Excel General
    Replies: 2
    Last Post: 10-10-2014, 05:42 PM
  4. Reducing values by x%
    By Leicia in forum Excel - New Users/Basics
    Replies: 9
    Last Post: 02-24-2013, 06:23 PM
  5. [SOLVED] Reducing a formula
    By Jaypelt in forum Excel General
    Replies: 19
    Last Post: 11-30-2012, 03:21 PM
  6. Reducing 2 spaces, down to 1
    By Tywardreath_NZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2009, 11:28 PM
  7. Can I reducing tab size...
    By Centrum in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-18-2007, 07:26 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