LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Macro to Find a specific data set and do a count

Sub Macro1()
Dim ws As Worksheet
Dim wb2 As Workbook
Dim ws2 As Worksheet
Dim iEnd As Integer
Dim iEnd2 As Integer
Dim str1 As String

'copy cols C, G & I from 5 wkbks to this one
Set ws = ThisWorkbook.Sheets("data_from_files")
For iCt = 1 To 5
Set wb2 = Workbooks.Open("c:\Temp\Book" & iCt & ".xls")
Set ws2 = wb2.Sheets("Sheet1")
iEnd2 = ws2.Range("C1").End(xlDown).Row
iEnd = 1 + ws.Range("A65536").End(xlUp).Row
ws2.Range("C2:C" & iEnd2).Copy ws.Range("A" & iEnd)
ws2.Range("G2:G" & iEnd2).Copy ws.Range("B" & iEnd)
ws2.Range("I2:I" & iEnd2).Copy ws.Range("C" & iEnd)
wb2.Close
Next iCt

'do advanced filter on copied data
iEnd = ws.Range("A65536").End(xlUp).Row
ws.Range("A1:C" & iEnd).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("E1"), Unique:=True
iEnd2 = ws.Range("E65536").End(xlUp).Row

'formula to count occurrences
str1 = "--(R2C[-7]:R" & iEnd & "C[-7]=RC[-3])," & _
"--(R2C[-6]:R" & iEnd & "C[-6]=RC[-2])," & _
"--(R2C[-5]:R" & iEnd & "C[-5]=RC[-1]))"
ws.Range("H2").FormulaR1C1 = "=SUMPRODUCT(" & str1
ws.Range("H2").Copy ws.Range("H3:H" & iEnd2)
End Sub

Hth,
Merjet

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to find specific data in a cell, then delete that row on down MultiMatt Excel Programming 1 May 15th 07 07:06 PM
HOw do i find and sort out data repeats for specific data set JRDePaul Excel Discussion (Misc queries) 0 February 26th 07 11:55 PM
count specific value with filtered data Shawn13 Excel Worksheet Functions 1 June 29th 06 12:27 AM
How do i create a macro to find a specific data? James Excel Programming 2 March 14th 06 07:56 AM
How do I count my data that are between specific values? LDC Excel Worksheet Functions 3 November 16th 04 11:14 PM


All times are GMT +1. The time now is 01:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"