Copying matched criteria plus relevant columns to new worksheet

I want to use code in a macro to search for criteria in a worksheet which 
allows the matched data to be copied (along with other relevant columns) to 
another worksheet in the same file.  Would this involve some sort of loop?  
Any help apreciated.

Thanks in advance,

Matt
0
7/29/2005 9:58:02 AM
excel.misc 78881 articles. 5 followers. Follow

3 Replies
371 Views

Similar Articles

[PageSpeed] 46

there are several ways to do it.

if you want to copy a hundred cells for three columns every time something 
in row 3 is matched 
somehting like the following could be used.

sub try()
tar=1  ' target column in sheet 2
for c = 1 to 34 step 3  ' this will be the look up column in sheet 1
if sheets("Sheet1").Cells(c,3)=comparison value  then
       for sr=1 to 100  'Source row
       for sc=0 to 2  ' source column
            sheets("Sheet2").Cells(sr,tar+sc)=sheets("Sheet1").cells(sr,c+sc)
      next sc
      next sr
      tar = tar +3
end if
next c
end sub

I would make it more formal with dim statements etc. for actual use

"mattguerilla" wrote:

> I want to use code in a macro to search for criteria in a worksheet which 
> allows the matched data to be copied (along with other relevant columns) to 
> another worksheet in the same file.  Would this involve some sort of loop?  
> Any help apreciated.
> 
> Thanks in advance,
> 
> Matt
0
BJ (832)
7/29/2005 11:51:04 AM
"mattguerilla" <mattguerilla@discussions.microsoft.com> wrote in message
news:7726E1C0-CA5B-469B-90C0-0FB322461DA6@microsoft.com...
> I want to use code in a macro to search for criteria in a worksheet which
> allows the matched data to be copied (along with other relevant columns)
to
> another worksheet in the same file.  Would this involve some sort of loop?
> Any help apreciated.
>
> Thanks in advance,
>
> Matt

Here's one way:
First copy your data sheet for manipulation in case something goes wrong.
Add a sheet for each criteria then loop thru your data, moving each matching
row to the corresponding sheet.

'copy input data to a temp worksheet then switch to it for maniupation in
case anything goes wrong
Sheets("Sheet1").Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "temp"

'add desitnation sheets for the matching data
    Sheets.Add.Name = "Match1"
    Sheets.Add.Name = "Match2"
    Sheets.Add.Name = "Match3"
    'copy title row to each of the new sheets
        For Each WS In Worksheets(Array("Match1", "Match2, "Match3"))
        WS.Range("A1:G1").Value = Sheets("Print").Range("A1:G1").Value
        Next

'any processing you do prior to seperating the matches needs completed here

'sort matching data to destination sheets
    Sheets("temp").Activate
    For Each cell In Range("G1:G" & Range("G65536").End(xlUp).Row)
    Select Case cell.Value
        Case "Match1":
        cell.EntireRow.Cut
Sheets("Match1").Range("A65536").End(xlUp).Offset(1, 0)

        Case "Match2":
        cell.EntireRow.Cut
Sheets("Match2").Range("A65536").End(xlUp).Offset(1, 0)

        Case "Match3":
        cell.EntireRow.Cut
Sheets("Match3").Range("A65536").End(xlUp).Offset(1, 0)
End Select
Next

'presuming you want to remove the temp worksheet once data is seperated,
without bothering the user
    Application.DisplayAlerts = False
    Sheets("temp").Delete
    Application.DisplayAlerts = True

'any followup processing goes here
end sub


0
Jefgorbach (42)
7/29/2005 2:25:00 PM
"Jef Gorbach" <Jefgorbach@aol.com> wrote in message
news:eYk8TlElFHA.3960@TK2MSFTNGP12.phx.gbl...
>
> "mattguerilla" <mattguerilla@discussions.microsoft.com> wrote in message
> news:7726E1C0-CA5B-469B-90C0-0FB322461DA6@microsoft.com...
> > I want to use code in a macro to search for criteria in a worksheet
which
> > allows the matched data to be copied (along with other relevant columns)
> to
> > another worksheet in the same file.  Would this involve some sort of
loop?
> > Any help apreciated.
> >
> > Thanks in advance,
> >
> > Matt
>
> Here's one way:
> First copy your data sheet for manipulation in case something goes wrong.
> Add a sheet for each criteria then loop thru your data, moving each
matching
> row to the corresponding sheet.
>
> 'copy input data to a temp worksheet then switch to it for maniupation in
> case anything goes wrong
> Sheets("Sheet1").Copy After:=Sheets(Sheets.Count)
> Sheets(Sheets.Count).Name = "temp"
>
> 'add desitnation sheets for the matching data
>     Sheets.Add.Name = "Match1"
>     Sheets.Add.Name = "Match2"
>     Sheets.Add.Name = "Match3"
>     'copy title row to each of the new sheets
>         For Each WS In Worksheets(Array("Match1", "Match2, "Match3"))
>         WS.Range("A1:G1").Value = Sheets("Print").Range("A1:G1").Value
>         Next
>
> 'any processing you do prior to seperating the matches needs completed
here
>
> 'sort matching data to destination sheets
>     Sheets("temp").Activate
>     For Each cell In Range("G1:G" & Range("G65536").End(xlUp).Row)
>     Select Case cell.Value
>         Case "Match1":
>         cell.EntireRow.Cut
> Sheets("Match1").Range("A65536").End(xlUp).Offset(1, 0)
>
>         Case "Match2":
>         cell.EntireRow.Cut
> Sheets("Match2").Range("A65536").End(xlUp).Offset(1, 0)
>
>         Case "Match3":
>         cell.EntireRow.Cut
> Sheets("Match3").Range("A65536").End(xlUp).Offset(1, 0)
> End Select
> Next
>
> 'presuming you want to remove the temp worksheet once data is seperated,
> without bothering the user
>     Application.DisplayAlerts = False
>     Sheets("temp").Delete
>     Application.DisplayAlerts = True
>
> 'any followup processing goes here
> end sub
>
>

Spotted a after sending: when copying the title row, sheets("print") should
have been sheets("temp")
Also during the matching, be sure to change column(g) to your longest data
column to catch everyone.


0
Jefgorbach (42)
7/29/2005 2:38:05 PM
Reply:

Similar Artilces:

DVD Copy Pro for Mac
[b]DVD Copy Pro for Mac[/b] is a DVD copy software that can support D9 to D5 compression. With simple operation, it can save DVD in four different ways including directly burning to DVD disc, saving as DVD folder, copying into DVD media format that can be played by DVD Player directly, and converting as ISO file for easy movie management. Now this cool Mac DVD Copy also supports the latest released Snow Leopard. You can download [b][url=http://www.dvd-copy-mac.net/download/dvd-copy-pro-mac.zip]DVD Copy Pro for Mac[/url][/b] freely right now. [b]More information:[/b][quote]http://www.dvd-...

Import/copy calendar in Outlook 2003
I got a new computer and installed Office 2003, and wanted to move my calendar to the new PC. I created a new data file called Personal Folders from Old PC. I wanted to copy my calendar OVER my current one in Personal Folders, but don't see a way to do so. I can copy my old calendar into the Pesonal Folders, but can't delete the new, empty Calendar. So I have Calendar, and Calendar 1 under my Personal Folders. Any way to just import/copy my reminders/appointments into my new calendar? Thanks for any advice. Ck G'Day Cathy, 1. Use the Folder List 2. Click on the OLD Cal...

Copy info from one workbook to another?
I have a problem I have a workbook with the function i want like a discribe here. The problem is i want to split the workbook but i don`t know how. Is it possible to have a main workbook with information from other workbooks at each worksheet? I have 20 workbooks with information. I would like to have a main workbook with on sheet1 every row from the 20workbooks with category1, on sheet2 every row from the 20workbooks with category2, etc, etc. The information in the 20workbooks in always only on sheet. The Colum in which the data is has no fix end. I go to fill in the rows trough a...

Cant se some columns! Why?
I have a spreadsheet that displays COL A and them col BL-BM-BN etc How do I get to see the cols B to BK I am working with EXCEL 2007 Thanks Either columns B through BK are hidden (most likely), or the Window is frozen and you've scrolled way over to the right, bringing column BL next to A. Assuming they're just hidden, Click on the 2 that identifies row 2 so that the entire row is selected, then On the [HOME] tab, in the CELLS group, pull down the "Format" list and choose Hide and Unhide and click the UNHIDE COLUMNS option. If its a Frozen window thin...

Secondary Copy
Hi, My customer using Great Plains modified report(Primary Copy). Now he wants new report something similar to the modified GP report with very few changes. I tried to copy the modified report and planned to use us a secondary copy. But the report has temp tables, so I am unable to make secondary copy. Can some one help me in how to make a new report something similar to the modified report, where to launch it. Whether it is possible throught VBA & Modifier? Regards Selvakumar.S A report with a temporary table can only be a primary copy. This is because only a primary copy can b...

local copy of mail
How do you store a copy of all your mail on you local computer when using Exchange? You setup an OST/Offline Folders file. Check with your mail admin if they support that configuration. "Brandon Baker" <brandon@discussions.microsoft.com> wrote in message news:epNKuJ19FHA.4004@TK2MSFTNGP14.phx.gbl... > How do you store a copy of all your mail on you local computer when using > Exchange? > ...

Unable to view champions league match purchased online
Hi, I have bought an online voucher to view the champions league match, However, i am getting the following error For instructions on how to resolve this issue please refer to our Frequently asked questions page, section Licence delivery error: A problem has occurred in the DRM component. Error Number: -1072879791 Error Description: A problem has occurred in the Digital Rights Management component. Contact Microsoft product support. Position: 1.1 Please help fast... thanks. Rutush What version of WMP and Windows? Does resetting the DRM cache help? Instructions ...

Error message when hiding columns
Has anyone seen this error message before when trying to hide columns? "Cannot shift objects off sheet." -- valenj ------------------------------------------------------------------------ valenj's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=24087 View this thread: http://www.excelforum.com/showthread.php?threadid=376912 maybe this'll help: XL: "Cannot Shift Objects Off Sheet" Error Hiding Columns http://support.microsoft.com/default.aspx?scid=kb;en-ca;211769 valenj wrote: > > Has anyone seen this error message before whe...

Money Plus Computer Transfer
Hello, I just got a new computer with Windows 7. I previously had Vista Home. However, I can't seem to get Money to work on the new computer. The old one is getting ready to sleep forever. Is there anything that I can do to get Money to work on my new computer or am I going to have to purchase a new Money Product.? Thank you, Install Money on the new W7 computer; copy your *.mny file to somewhere in the Documents tree - do NOT put in Program Files area (W7 doesn't like it). First time right click on the desktop icon for Money and select Run as Administrator. ...

Copy picture ossice wizard
I have project 2007 standard edition, but the button is not working at all? Any suggestions Hi, The wizard is IMHO useless. Go to Roport, Copy Picture and do without the Wizard what millions have done before the Wizard existed. HTH -- Jan De Messemaeker Microsoft Project Most Valuable Professional +32 495 300 620 For availability check: http://users.online.be/prom-ade/Calendar.pdf "Enrique" <Enrique@discussions.microsoft.com> wrote in message news:72B5AA6C-67AE-468D-B6AE-FF16F52E57BD@microsoft.com... >I have project 2007 standard edition, but the bu...

Moving Outlook to a new computer #2
I am trying to move my Outlook 2003 to a new computer and can not see how to move all of my customization with it. For example, the catagories additions I made and all of the rules I set up for lables. Can someone point me to an article that gives you the details? Thanks ...

Between Dates Criteria
Can’t' seem to get it. I have two fields: Start_Date and End_Date. Both are Short Date Format. Note: Both date fields are previously calculated dates from the original "Review_Date field. Like, Review_Date+10 is the Start_Date and Review_Date+20 is the End_Date. I want to use a between dates criteria using both fields. I have researched and tried so many combinations to list here without success. **** The dates I ask for are never correct, or within the parameter entered. Either one or the other is off. I have even tried two parameters, [Enter Start Date] on...

Columns won't Hide!
I'm trying to hide columns in a ss and I get the message, "Cannot Shift Objects off Sheet.". I'm able to hide some columns but Excel seems to reach a limit. Help! You may have something in columns that you don't know about. "Tom" <thomas.hamilton@med.va.gov> wrote in message news:051e01c38d97$7b458e80$a001280a@phx.gbl... > I'm trying to hide columns in a ss and I get the > message, "Cannot Shift Objects off Sheet.". I'm able to > hide some columns but Excel seems to reach a limit. > > Help! >-----Original Mess...

Outlook 2000 SP3
How can I copy my mail and calendar to CD so that I can take my received and sent mail history to a new computer with Outlook installed? Thanks. >-----Original Message----- >How can I copy my mail and calendar to CD so that I can >take my received and sent mail history to a new computer >with Outlook installed? Thanks. >. > All your data saves in C:\Documents and Settings\Username\Local Settings\Application Data\Microsoft\Outlook\archive.pst and C:\Documents and Settings\Evgeni\Local Settings\Application Data\Microsoft\Outlook\outlook.pst You can either install instan...

Text to column and paste special transpose
Hi All, I have 1 table like this item_number qty ref 00010-001 3 U34,U36,U43 00013-001 2 U16,U21 12505-001 3 U32,U33,U42 12512-001 3 U5,U6,U27 and 1 want it to become like this item_number qty ref 00010-001 3 U34 00010-001 3 U36 00010-001 3 U43 00013-001 2 U16 00013-001 2 U21 12505-001 3 U32 12505-001 3 U33 12505-001 3 U42 12512-001 3 U5 12512-001 3 U6 12512-001 3 U27 Anybody can help me to program it in macro.. usually i do it manually and have to redo again do to careless. After using Text to Columns on Column C.......comma delimited.........Run the Reorganize macro. Sub ReOrganize...

Email trouble with New User in Active Directory
Below is a trail of posts that have been made. My problem has yet to resolved and I need some help quickly. The only other thing I can think of is to reinstall Exchange Server 2003. Hopefully someone will know the answer. Thanks! Subject: Re: Email not Setup when new user created in Active Directory From: "Bryan Hill" <bthill@comcast.net> Sent: 8/15/2004 12:30:21 PM We have other clients that are working fine. Just when we try to set up new ones - it will create the SMTP address but not the X400 address. I tried manually forcing the X400 but it will...

Matching records in SOP10106
We have a custom invoice printing where the query relies on joining records in SOP30200 with SOP10106 table but just came across some invoices that don't have any matching records in SOP10106. Of nearly 200,000 invoice records in our SOP30200 table there are only 19 that I've found (with soptype=3 and voidstts=0) that doesn't have associated records in the SOP10106 table. Can anyone tell me in what certain condition this would happen? FYI, I'm a developer not familiar with how GP works and accounting in general. TIA. John, SOP10106 stores values from the various User...

Copy and paste versus copy and insert copied cells
What is the difference between these commands? Try them, it is pretty easy to see the difference -- Regards, Peo Sjoblom "Alana" <Alana@discussions.microsoft.com> wrote in message news:879FED29-5541-41B0-BB2C-7108D42ED593@microsoft.com... > What is the difference between these commands? ...

subtotal copy and paste
Hi I have used the subtotal option in Excel and this is fine. I have also collasped the list so only the subtotal for each category is visible. However I want to copy and paste this list (just the subtotal) into another sheet When I do this it expands and shows all the results. Is it possible to just copy the visible bit. I have looked in paste special but no luck Cheers Hager On Jan 21, 6:38=A0am, Hager <Ha...@discussions.microsoft.com> wrote: > Hi > > I have used the subtotal option in Excel and this is fine. I have also > collasped the list so only the...

Create New Report
Hi there, To set the scene, i'm using web client of 4.0, and i'm not a programmer. Currently, out-of-the-box functionality allows you to run a report called "Quote" which presents the data in a good format, almost good enough to hand to a customer. What I need is this report, but with our logo's embedded, and a few fields added/moved/removed, but i can't figure out how to edit layout options or content options, and I can't even seem to create a similar report from scratch (as they all appear to relate to exisitng XML reports out of the box). I'll be...

3D Column Chart #2
How do I create a 3D column chart and have three axis? ...

Copy above fails one way, copy below fails another way
I have a table of blood pressure readings that looks something like this: A B C D E 11 12 Averages: 134 83 74 13 R# Date Sys Dia Pul 14 4 8/17/08 138 87 72 15 3 8/15/08 130 84 76 16 2 8/12/08 137 83 70 17 1 8/11/08 129 79 76 Cell A14 contains =A15+1 Cell C12 contains =AVERAGE(C14:C17) Cell D12 contains =AVERAGE(D14:D17) Cell E12 contains =AVERAGE(E14:E17) Every time I take a new reading, I want to add a row to the top of the table, between row 13 (the header) and row 14 (the previous top row). I want to push a...

limit number of rows 7 colloms in a worksheet
is there a way to limit or set the number of rows & collums in a worksheet ? thanks david --- Message posted from http://www.ExcelForum.com/ "davidbrowne17" <davidbrowne17.ya1sm@excelforum-nospam.com> wrote in message news:davidbrowne17.ya1sm@excelforum-nospam.com... > is there a way to limit or set the number of rows & collums in a > worksheet ? No. All worksheets have 256 columns by 65536 rows. You can hide unused rows/columns. But why bother? Hi David, Put this in the ThisWorkbook code module. Adjust to suit the area. Private Sub Workbook_Open() Wo...

column headings in numbers vs letters
For some reason all my excel files now display columns as numbers rather than letters. How can I change back to letters? Why are all my old files also now reading in numbered columns? This is a setting of Excel, not of your files. Tools>Options>General, uncheck R1C1 Reference style -- Kind Regards, Niek Otten Microsoft MVP - Excel "garyflood" <garyflood@discussions.microsoft.com> wrote in message news:6870D172-C11D-4FF9-A7D8-48BE89149DF8@microsoft.com... > For some reason all my excel files now display columns as numbers rather > than > letters. How...

Business Portal "Copy to Excel" not working in Query pages
Hi, I am using Business Portal 4.0. When browsing through one of the queries pages in Business Portal, i clicked "Copy to Excel" icon. I got an error saying "The Office Web Components (OWC) must be installed to copy results to Excel." at the bottom. I am using Office 2007 on my machine. I came to know that Microsoft Office Web Components will no longer be shipping in Microsoft Office. I tried installing Office 2003 Add-in: Office Web Components from http://www.microsoft.com/downloads/details.aspx?familyid=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=en a...