Friday, September 23, 2016

How to Fix Problem - counting populated cells in multiple workbooks?

counting populated cells in multiple workbooks

I have 12 workbooks, named Jan,Feb,Mar etc....
each workbook has 31 sheets - 1 for each day of the month
a list of account numbers is entered into column c (c17:c117) for each day of each month for various tracking purposes


column a
column b
column
c
column d
column e



acct #





123-123





456-456





789-789





In a separate workbook named "YTD 2013" i have a sheet "Daily referrals" which tracks the number of accounts for each day of each month - columns labeled JAN (cells a1:a31) FEB (b1:b31) and so on for the entire year -

i currently enter these numbers manually into the "Daily referrals" sheet, and use SUM to find the totals of each column


day
JAN
FEB
MAR

1st
6
4


2nd
13
15


3rd
8
22


4th
4
7


totals






I would like to automate the process - counting the number of accounts entered each day from each monthly workbook, and have that total added to the "daily referrals" sheet

I thank you in advance for any help you could provide

Brian

Keys to the Problem counting populated cells in multiple workbooks

Download Error Fixer for Free Now

Assumptions made in generating the code below:
  The monthly workbooks are named like JAN.xlsx ...
DEC.xlsx
  All monthly workbooks are in a single folder
  The YTD 2013 workbook will also be in that same folder!
  The 29/30/31 daily sheets in a month's folder will be named simply "1", "2" ...
"31"
 
To test this - create a test folder, copy a set of monthly files into it and place a copy of the YTD workbook with the code below in it into that same folder.  If it all works well, you can move the YTD file into the real-world folder and delete the entire
test folder.
 
This code goes into a Regular code module, and you can find instructions on getting it from here into one of those in the YTD workbook here:
http://www.contextures.com/xlvba01.html#videoreg
Be sure your YTD workbook is saved as a macro enabled workbook, type .xlsm (or .xlsb).
 
There are lots of Const declarations that define how things are set up in the two workbooks.  I think they should be good to go right now, but if your sheet layouts are different than I've imagined, you can simply change those Const values (part to the right
of the = symbol) to match reality and the code will work properly for you.  This also allows you to adapt the code in the future if the layout of the workbooks/worksheets changes.  I've marked them in bold in this posting.
 
Here is the code:
 
Sub UpdateDailyReferralsCounts()
  'Change these constants to reflect actual
  'layout and content of your workbooks
  ' the layout of the 'Daily Referrals' sheet
  ' in this workbook
  Const drSheetName = "Daily Referrals"
  'assumed that Feb-Dec are adjacent to each other
  ' i.e., Feb is in C, Dec is in M
  Const janColumn = "B" ' column for January entries
  Const decColumn = "M"
  Const day1Row = 2 ' assumes row 1 has month titles
  Const day31Row = 32 ' 31 days per month
  '
  'these 'define' the layout of the daily sheets
  'in each of the monthly workbooks
  Const acctColumn = "C"
  Const acctFirstDataRow = 2 ' assumes labels in row 1
  'assumed that all monthly files are .xlsx type files
  'so if they are .xlsm or .xls files, just change this constant
  Const monthFileType = ".xlsx"
  'set up to be able to reference the monthly files
  Dim monthlyWBs As Variant
  'set the array contents to the name of the
  '12 monthly workbooks, you can change these if
  'you have them named differently as by month+year
  'this creates an array, monthlyWBs(0 to 11) with filenames in it
  monthlyWBs = Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", _
   "AUG", "SEP", "OCT", "NOV", "DEC")
  'end of user (re)definable information
  'working variables for the process
  Dim basicPath As String ' all files including this on are to be in same folder
  Dim monthlyWB As Workbook   'will reference a monthly Workbook
  Dim monthlyWS As Worksheet  'will reference sheets 1-31 in a monthly Workbook
  Dim acctsRange As Range ' will refer to used cells in column C
  Dim myDRSheet As Worksheet  'will reference [Daily Referrals] sheet
  Dim MLC As Integer ' to loop through the monthlyWBs array
  Dim DLC As Integer ' to loop through sheets 1-31 in monthly workbooks
  Dim anyLastRow As Long
  Dim dayRowPointer As Integer
  Dim monthColPointer As Integer
 
  basicPath = ThisWorkbook.Path
  'currently we need to add the final / to path, but
  'that may change in the future, so allow for it now.
  If Right(basicPath, 1) <> Application.PathSeparator Then
    basicPath = basicPath & Application.PathSeparator
  End If
  'start by deleting all existing information in the
  'Daily References worksheet!
  Set myDRSheet = ThisWorkbook.Worksheets(drSheetName)
  myDRSheet.Range(myDRSheet.Cells(day1Row, janColumn), _
   myDRSheet.Cells(day31Row, decColumn)).ClearContents
  'now ready to refill the data
  '
  Application.ScreenUpdating = False
  For MLC = LBound(monthlyWBs) To UBound(monthlyWBs)
    'set up pointer to proper column on Daily Referrals sheet
    monthColPointer = Range(janColumn & 1).Column + MLC
    Set monthlyWB = Workbooks.Open(basicPath & monthlyWBs(MLC) & monthFileType)
    'set up row pointer for the Daily Referrals sheet
    dayRowPointer = day1Row ' reset/initialize
    For DLC = 1 To 31
      'assumes sheet names in monthly sheets are simply
      'the day of the month, as "1", "2" ...
"31"
      On Error Resume Next
      Set monthlyWS = monthlyWB.Worksheets(CStr(DLC))
      If Err = 0 Then
        'the sheet exists, process it
        anyLastRow = monthlyWS.Range(acctColumn & Rows.Count).End(xlUp).Row
        Set acctsRange = monthlyWS.Range(acctColumn & acctFirstDataRow & ":" _
         & acctColumn & anyLastRow)
        'put the daily count onto the daily referrals sheet
        myDRSheet.Cells(dayRowPointer, monthColPointer) = _
         Application.WorksheetFunction.CountA(acctsRange)
      Else
        'sheet did not exist (as may not for 28/29/30 day months)
        Err.Clear
      End If
      On Error GoTo 0
      dayRowPointer = dayRowPointer + 1
    Next ' end DLC loop
    Application.DisplayAlerts = False
    monthlyWB.Close False ' close without saving changes
    Application.DisplayAlerts = True
  Next ' end MLC loop
  'housekeeping and cleanup
  Set myDRSheet = Nothing
  Set acctsRange = Nothing
  Set monthlyWS = Nothing
  Set monthlyWB = Nothing
  'announce job completed
  MsgBox drSheetName & " entries have been updated.", vbOKOnly, "Task Completed"
End Sub

Manually editing the Windows registry

Caution: Unless you an advanced PC user, please do not edit the Windows registry manually.

Because of this risk, we highly recommend using a trusted registry cleaner such as SmartPCFixer Using a registry cleaner automates the process of finding invalid registry entries, missing file references (like the one causing your MACHINE_CHECK_EXCEPTION error), and broken links within the registry. A backup is automatically created before each scan, with the ability to undo any changes in a single click, protecting you against the possibility of PC damage. The best part is that repairing registry errors can also dramatically improve system speed and performance.

  • Click the Start button.
  • Type "command" in the search box... DO NOT hit ENTER yet!
  • While holding CTRL-Shift on your keyboard, hit ENTER.
  • You will be prompted with a permission dialog box.
  • Click Yes.
  • A black box will open with a blinking cursor.
  • Type "regedit" and hit ENTER.
  • In the Registry Editor, select the Error 0x9C-related key (eg. Windows Operating System) you want to back up.
  • From the File menu, choose Export.
  • In the Save In list, select the folder where you want to save the Windows Operating System backup key.
  • In the File Name box, type a name for your backup file, such as "Windows Operating System Backup".
  • In the Export Range box, be sure that "Selected branch" is selected.
  • Click Save.
  • The file is then saved with a .reg file extension.
  • You now have a backup of your MACHINE_CHECK_EXCEPTION-related registry entry.

The next steps in manually editing your registry will not be discussed in this article due to the high risk of damaging your system. If you would like to learn more about manual registry editing, please see the links below.

Recommended Method to Fix the Problem: counting populated cells in multiple workbooks:

How to Fix counting populated cells in multiple workbooks with SmartPCFixer?

1. Download Error Fixer . Install it on your system.  Click Scan, and it will perform a scan for your computer. The errors will be shown in the list.

2. After the scan is done, you can see the errors and problems need to be repaired. Click Fix All.

3. When the Fixing part is finished, your computer has been speeded up and the errors have been removed


Related: How Can You Update & Download NVidia 6100, 6800 GS/XT Display Driver v.260.89 WHQL,Where to Download NVidia GeForce 8800 GT WHQL-certified driver v.196.21,How to Update & Download NVidia GeForce Go 7400 Display Driver v.260.19.12,[Solved] Download NVidia GeForce GTX 460M Driver v.331.82,Download NVidia Quadro Plex Model IV VGA Driver v.304.43 Certified,Way to Download RealTek RTL8100C(L) Driver v.5.01,Way to Download RealTek RTL8100E Drivers v.694,Way to Update & Download RealTek RTL8101L Auto Installation Program v.6.110 driver,Method to Update & Download RealTek RTL8111G PXE and RPL ROM code v.2.58 driver,How to Update & Download RealTek RTL8411B(N) Driver v.10.003,Best Way to Update & Download ASUS A53SV nVidia Graphics Driver v.8.17.12.6686,Method to Herunterladen ASUS K75VJ Intel Rapid Storage Technology Treiber v.11.6.0.1030,How Can You Update & Download ASUS CG8580 Intel Chipset Driver v.9.3.0.1019,Method to Update & Download ASUS K41VD Intel INF Update Driver v.9.1.1.1015,Way to Update & Download ASUS Pro70T NB Probe v.3.0.0026 driver
Read More: Fast Solution to Error: Convert formula in specific cells to value they currently contain,convert columns with rows data into a single column with rows Tech Support,Troubleshooting:copy data from one sheet to multiple different sheets Error,Troubleshooting:Could not add page numbers, headers and footers. Pls i really need this help.Anybody please?,Fast Solution to Problem: create a system repair disc error (0x80070057).,Closing Internet Explorer causes error,Compare 2 Tables and Calculate the PROFIT Faster,Computer goes to Windows Boot Manager after Start,Connect to one of my network computer remotely when don't allow exception box Marked,computer locking up randomly

No comments:

Post a Comment