Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 04-12-2011, 07:25 AM
macropod's Avatar
macropod macropod is offline HLOOKUP, if,? OR MACRO Windows 7 32bit HLOOKUP, if,? OR MACRO Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Bobby,

Here's a commented version of the sub. These should help you understand what's going on.

The code doesn't look at the Weld ID at all. If you were to name your various worksheets with the Weld IDs, then another loop could be set up to go through those worksheets and, based on their names, put the output data in the corresponding columns on the 'summary' sheet. Or you could stick with what you've got and have the code look at the Weld IDs in Column A of each sheet. Either way, additional logic and looping will be required for the code to work with multiple tabs.
Code:
Sub Summarize()
'Disable ScreenUpdating for speed
Application.ScreenUpdating = False
'Define variables
Dim i As Long, j As Long, k As Long
Dim StrName As String, iTally As Long
'Start with the list of welders on Sheet2
With ThisWorkbook.Sheets("Sheet2")
  'Get each used row on Sheet2
  '.Range("A" & .Rows.Count).End(xlUp).Row locates the last row
  For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
    'Store the welders' name
    StrName = .Range("A" & i).Value
    'Set the weld count to 0
    iTally = 0
    'Look in Sheet1
    With ThisWorkbook.Sheets("Sheet1")
    'Get each used row on Sheet1
    '.Range("A" & .Rows.Count).End(xlUp).Row  locates the last row
      For j = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
        'Get each used column on Sheet1
        '.Cells.SpecialCells(xlCellTypeLastCell).Column  locates the last column
        For k = 2 To .Cells.SpecialCells(xlCellTypeLastCell).Column
          'Test whether the cell for the current row/column matches the welder's name
          If .Cells(j, k).Value = StrName Then
            'If it is, increment the tally, then skip the rest of this row
            iTally = iTally + 1
            Exit For
          End If
        Next k 'Check the next column for this row
      Next j 'Check the next row
    End With
    'update the welder's tally count
    .Range("B" & i).Value = iTally
  Next i 'Get the next welder
End With
'Restore ScreenUpdating
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Tags
counta, countif, hlookup



Similar Threads
Thread Thread Starter Forum Replies Last Post
HLOOKUP, if,? OR MACRO Help with a macro Takket Word VBA 2 03-28-2014 04:58 PM
need a macro that does the following atomsk Word VBA 0 07-05-2010 07:29 AM
Please help Jarrod Word 1 06-05-2010 06:31 AM
I need a macro, who can help me? Bahir Barak Word VBA 1 05-26-2010 12:24 AM
Macro help NEHicks503 Excel 0 04-16-2010 07:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft