Consulting

Results 1 to 2 of 2

Thread: Revising A VBA Code

  1. #1
    VBAX Regular
    Joined
    May 2020
    Posts
    6
    Location

    Red face Revising A VBA Code

    Hi, everyone
    I have a code for summarizing personnel work time while it's sensitive to 8 hours shift, means if the user types work time for a personnel in a specific date which their cumulative work time exceeds 8 hours, this code omits it and just write 8 hours for that personnel in that date. This code was wrote by my friend but I want to develop it to my real world problem in excel. In the last command, you see there is SumIfs object which refers to limited rows. I want to develop it to all rows in those determined columns. So, if I write my data till row 15233 (my real data in huge), there is no need to make any change in the code. I don't know how to make such a change in my code. I'm new to VBA. Please help me to learn.
    Attached Files Attached Files

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    Sub SummarizeData()Dim LR As Long, BR As Long
    
    
    With ActiveSheet
        
        BR = .Range("G" & .Rows.Count).End(xlUp).Row
        If BR > 1 Then .Range("G1").CurrentRegion.ClearContents
        
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        .Range("A1:C" & LR).Copy .Range("G1")
        BR = .Range("G" & .Rows.Count).End(xlUp).Row
        
        .Range("G1:I" & BR).RemoveDuplicates Columns:=Array(1, 3), Header:=xlYes
        BR = .Range("G" & .Rows.Count).End(xlUp).Row
        
        .Sort.SortFields.Clear
        .Sort.SortFields.Add Key:=Range("G2:G" & BR), Order:=xlAscending
        .Sort.SortFields.Add Key:=Range("I2:I" & BR), Order:=xlAscending
        With .Sort
            .SetRange Range("G1:I" & BR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        .Range("H2:H" & BR).FormulaR1C1 = "=MIN(8, SUMIFS(R2C2:R16C2, R2C1:R16C1,RC[-1], R2C3:R16C3,RC[1]))"
    End With
    
    
    End Sub

Posting Permissions

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