Excel VBA Sum from Multiple Sheets

前端 未结 3 427
情话喂你
情话喂你 2021-01-26 04:01

I am trying to create a function or functions that can sum daily hours from time cards for each client to come up with the total hours worked per day. Each client has it\'s own

3条回答
  •  [愿得一人]
    2021-01-26 04:42

    I didn't understand ur question completely but As I understood u have different sheets of different clients which contains supoose column 1 date and column 2 contains hours on that particular date wise hours and a final sheet which column1 contains name of client and column 2 contains total hours
    Please try it

    Sub countHours()
    Dim last_Row As Integer
    Dim sum As Double
    sum = 0
      'Because I know number of client
       For i = 1 To 2     'i shows client particular sheet
    
      last_Row = Range("A" & Rows.Count).End(xlUp).Row
    
      Sheets(i).Activate
    
      For j = 2 To last_Row
    
      'In my Excel sheet column 1 contains dates and column 2 contains number of hours
    
      sum = sum + Cells(j, 2)
      'MsgBox sum
      Next j
    
      'Sheet 3 is my final sheet
      ThisWorkbook.Sheets(3).Cells(i + 1, 2).Value = sum
      sum = 0
      Next i
    
      End Sub
    

    Happy Coding :

提交回复
热议问题