Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search , then copy and paste from multiple worksheets. VBA help

HI,
Here's what I have
1. A summary sheet with rows for each candidates. looks sth like this.

Gemma Anthony P. Male House RI 1
Lynch William J. Male House RI 1

2. 15 files containing individual worksheets for each candidate whose data needs to be aggregated. e.g. sheet 1 for Gemma, sheet 2 for Lynch.

I aim to accomplish these steps with a macron:
1. SEARCH for the individual sheet that contains candidate last name (column A in summary sheet,column A in individual sheet followed by first name )
2. ACTIVATE this individual sheet, COPY a certain range of cells (K1:K70, the same for all sheets)
3. PASTE SPECIAL these cells (select only values, transpose) to the summary sheet, at P CELL of the row of the candidate.

I appreciate your help in advance. If you think this is difficult, can you assess its level of complexity so that I could seek appropriate help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Search , then copy and paste from multiple worksheets. VBA help

Hello,

The macro I wrote below should work (assuming that I fully understood your parameters). You may need to tweak it in a few places for it to work. I included a lot of comments to help you determine what changes might be necessary.

Hope this helps,
Ben

Sub CopyCandidates()
Dim wsSummary As Worksheet
Dim ws As Worksheet
Dim rNames As Range
Dim strCopyRange As String
Dim rC As Range

strCopyRange = "K1:K70" 'Range to copy as a string
Set wsSummary = Sheet1 'Summary sheet
Set rNames = wsSummary.Range("A1:A15") 'Range with Names to search

Application.ScreenUpdating = False 'Increases speed of macro

For Each rC In rNames 'For each cell in the Name list...
For Each ws In ThisWorkbook.Worksheets '...loop through each sheet to find the Name
ws.Activate 'Activate the sheet first
If ws.CodeName = wsSummary.CodeName Then GoTo NextSheet 'Skip the Summary sheet
On Error Resume Next 'Skips errors when not found
ws.Range("A:A").Find(What:=rC.Value, After:=ws.Range("A10000"), LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:= _
False, SearchFormat:=False).Activate 'Try to activate the found cell
If Err.Number = 0 Then 'Found cell could be activated...
ws.Range(strCopyRange).Copy '...so copy the data...
rC.Offset(0, 15).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True '...and paste as values, transposed to column P of Summary
GoTo NextCell 'No need to search remaining sheets, so move on to next name
Else
Err.Clear 'If it was an error, then Name not found, clear the error for next sheet.
End If
NextSheet:
Next ws
NextCell:
Next rC

'Clean up the variables and return the application to normal
Application.CutCopyMode = False
wsSummary.Activate
Application.ScreenUpdating = True

Set wsSummary = Nothing
Set ws = Nothing
Set rNames = Nothing
Set rC = Nothing

End Sub
Reply
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
Copy & paste macro for multiple worksheets tomhelle Excel Discussion (Misc queries) 8 March 15th 10 06:21 PM
search, copy and paste through multiple sheets Jeff S.[_2_] Excel Discussion (Misc queries) 1 August 16th 09 12:08 AM
Looping: Search Range in Multiple Selected Worksheets, Copy/Paste ryguy7272 Excel Programming 6 April 2nd 07 04:50 PM
copy multiple worksheets of a workbook, and paste onto a Word document ( either create new doc file or paste onto an existing file.) I need this done by VBA, Excel Macro Steven Excel Programming 1 October 17th 05 08:56 AM
multiple search criteria to find and copy from sheet1 and paste into sheet2 lothario[_54_] Excel Programming 2 November 25th 03 09:57 AM


All times are GMT +1. The time now is 04:09 PM.

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"