PC Review


Reply
Thread Tools Rate Thread

Creating a unique list of Cost Codes in Col. A from all worksheets in all workbooks in folder X

 
 
u473
Guest
Posts: n/a
 
      22nd Oct 2007
How do I create in a new Workbook, a unique list of Cost Codes in Col.
A from all worksheets in all workbooks in folder X. , in a grid
format to be able to detect less used codes as follows:

Code WBA-Sh1 WBA-Sh2 WBB-Sh1 WBB-Sh2 WBB-Sh3 Total
X 1 1
1 3
Y 1 1
1 1 4
Z 1
1 2
WBB-Sh3 = Workbook B Sheet 3
Thank you again for the help to all the Gurus.
Celeste

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      22nd Oct 2007
The code below should work

Put the codes you want to look up in the new workbook in column A starting
in row 2. The macro also will go in the new workbook. Change Mypath to the
appropriate path. the code will automatically put the workbook name and
worksheet in the first row for each sheet it counts. The code uses the
worksheet function Countif to get the totals.


Sub addcostcodes()

Const MyPath = "c:\temp"

With ThisWorkbook.Sheets("sheet1")
Sh1Lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
ColumnCount = 2
First = True
Do
If First = True Then
Filename = Dir(MyPath & "\*.xls")
First = False
Else
Filename = Dir()
End If
If Filename <> "" Then

Workbooks.Open MyPath & "\" & Filename
For Each ws In ActiveWorkbook.Worksheets
.Cells(1, ColumnCount) = _
ActiveWorkbook.Name & " - " & _
ActiveSheet.Name
Lastrow = ws.Cells(Rows.Count, "A"). _
End(xlUp).Row
Set SearchRange = Range("A2:A" & Lastrow)

For Sh1rowCount = 2 To Sh1Lastrow
costcode = .Range("A" & Sh1rowCount).Value
Count = WorksheetFunction.CountIf(SearchRange, costcode)
.Cells(Sh1rowCount, ColumnCount) = Count
Next Sh1rowCount
ColumnCount = ColumnCount + 1
Next ws
Workbooks(Filename).Close
End If
Loop While Filename <> ""
End With
End Sub


"u473" wrote:

> How do I create in a new Workbook, a unique list of Cost Codes in Col.
> A from all worksheets in all workbooks in folder X. , in a grid
> format to be able to detect less used codes as follows:
>
> Code WBA-Sh1 WBA-Sh2 WBB-Sh1 WBB-Sh2 WBB-Sh3 Total
> X 1 1
> 1 3
> Y 1 1
> 1 1 4
> Z 1
> 1 2
> WBB-Sh3 = Workbook B Sheet 3
> Thank you again for the help to all the Gurus.
> Celeste
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a total cost chart where a component cost is a step cost gvm Microsoft Excel Charting 0 28th Apr 2010 02:10 PM
Creating a list from multiple (sometimes the same) codes David Microsoft Excel Misc 1 9th Mar 2010 04:12 PM
Simple Folder, Workbooks, Worksheets Import ? u473 Microsoft Excel Programming 1 16th Apr 2008 09:11 PM
creating unique new worksheets stuph Microsoft Excel Programming 2 4th Feb 2004 11:25 PM
creating workbooks and worksheets automatically from existing ss Neil Microsoft Excel Programming 1 26th Jul 2003 03:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:48 PM.