VBA to move rows to another sheet based on criteria

JSR1306

New Member
Joined
Sep 15, 2012
Messages
45
Hi all,

I am sorry if this has been explained already but I cant find anything that quite does what I want.

Basically I have a table as follows with about 1000 lines of data.

ReferencePrioritystatusdescriptiondue datedate submitted
1232Openabc01/03/1311/02/13
1342Openjhg02/03/1311/02/13
1241AWC kli01/03/1311/02/13
3213AWCijk01/03/1311/02/13
5264Escalatedyhu02/03/1311/02/13
9814Escalatedjhy01/03/1311/02/13
8522Openabd01/03/1311/02/13

<tbody>
</tbody>

Basically I want to sort these into separate sheets under the headings of the status column. I have tried writing macros however this is very messy and I am sure there is a better way of coding it.

I have also tried some code such as the following:

Sub go()


Dim StsCol As String


Sheets("Report").Select


StsCol = Application.Range("A1000").End(xlUp).Row


a = 1




For i = 1 To StsCol

Sheets("Report").Select
If Range("C" & i).Value = "Open" Then
Range("C" & i).EntireRow.Copy
Sheets("T1 Open").Select
ActiveSheet.Range("A" & a).Select
Selection.PasteSpecial (xlValues)
a = a + 1
End If
Next

MsgBox "Done!"


End Sub


This does work on sorting the Open into a separate sheet, however, it is very slow and you the screen just blinks rapidly as it finds a row with Open and copies, then pastes it to the correct sheet.

I am not great a VB so any help is greatly appreciated. Hopefully I will learn something in the process :)

Many Thanks

John
 
Matheson843,

Welcome to the MrExcel forum.

I would think that your raw data structure is different.

Please do not post your questions in threads started by others - - this is known as thread hijacking.
Always start a new thread for your questions and, if you think it helps, provide a link to any other thread as a reference.
Start a new thread for your question and be sure to give it a search friendly title that accurately describes your need.


After you create a new thread, please send me a Private Message with a link to your new thread, and, I will have a look.


In your new thread:

What version of Excel are you using?

Can you post a screenshot of the raw data worksheet, and, post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel HTML Maker


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Last edited:
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi Texaslynn,

I understand I should be starting a new thread for my own question. However, my question directly relates to the one already posed here and refers specifically to the code you posted.

The code you have posted works perfectly. However, I already have a tab with a name that matches one of the data names in the column that is being broken out. When the macro runs, the already created tab is overwritten with the data that is being broken out from the selected column.

My question: Is there a way to break out data based on what is in column "A". While naming the new sheet the same as the data but with a variant such as (2) or (a) at the end of the name.


Example: I already have a tab for "Ford" however I am trying to break out the data into new sheets based on column A "Cars." When I run your macro the pre-existing "Ford" tab is overwritten by the data broken out from column A "Cars." I would like to be able to break the data in column A "Cars" into tabs such as "Ford(a)" or "Ford(2)" so that the data doesn't overwrite. Is this possible? Thanks in advance!!!


CarsPriceYearColor
Ford30K2011Blue
Chevy38K2013Green
Ferrari60K2012Red
Nissan40K2010Red
Toyota25K2011Black
Honda26K2010White

<COLGROUP><COL style="WIDTH: 48pt" span=4 width=64><TBODY>
</TBODY>
 
Last edited:
Upvote 0
Do you know why I am getting stuck here?

ReDim SheetNameArray(1 To Rng2.Cells.Count)
SheetNameArray = fn.Transpose(Rng2)
.Columns(lastCol + 2).Clear
 
Upvote 0
Do you know why I am getting stuck here?

ReDim SheetNameArray(1 To Rng2.Cells.Count)
SheetNameArray = fn.Transpose(Rng2)
.Columns(lastCol + 2).Clear

What is "fn"? Transpose is a method of the WorksheetFunction object, so unless "fn" references that object, your code line won't work. Try changing "fn" to "WorksheetFunction" (without the quotes, of course) and see if that gets your code working (although I have some concern about that dot in front of the last line given that you did not show a With statement whose object it would be referencing). Note that is usually quite hard to diagnose a problem from a small snippet of code taken from a larger procedure as we cannot see what the intention of the code is nor what has taken place prior to the code snippet being evaluated.
 
Last edited:
Upvote 0
Hello,

I have a similar but different action I am trying to achieve and have run through various other VBA macro's with failed results.

Basically I have a two step process I need to complete, the data set I have to filter and only true values should be copied to the adjacent sheet(s)

Step one: Each data line has an ID number with several values that follow, these lines are presorted by time/date in descending order (oldest to newest). I need to compare duplicate ID's (could be two or three or more) to meet criteria before its considered true. So if my target criteria is ">5" I need to compare duplicate ID's for that value, if the newest (chronological) ID value exceeds the target, it is true

Example of a true (because the newest value is greater than 5):

Date Time ID Value
2/4/2015 17:25 250 4.2
2/5/2015 16:23 250 3.5
2/5/2015 16:25 250 5.1

Example of a false (because the newest value is less than 5):

Date Time ID Value
2/4/2015 17:25 252 6.8
2/5/2015 16:23 252 5.5
2/5/2015 16:25 252 4.3

Step two: true values should carry the entire column of data (just the true column of data, not the false ones) to the adjacent sheet

Any help is greatly appreciated
 
Upvote 0
Hello,

I have a similar but different action I am trying to achieve and have run through various other VBA macro's with failed results.

Basically I have a two step process I need to complete, the data set I have to filter and only true values should be copied to the adjacent sheet(s)

Step one: Each data line has an ID number with several values that follow, these lines are presorted by time/date in descending order (oldest to newest). I need to compare duplicate ID's (could be two or three or more) to meet criteria before its considered true. So if my target criteria is ">5" I need to compare duplicate ID's for that value, if the newest (chronological) ID value exceeds the target, it is true

Example of a true (because the newest value is greater than 5):

Date Time ID Value
2/4/2015 17:25 250 4.2
2/5/2015 16:23 250 3.5
2/5/2015 16:25 250 5.1

Example of a false (because the newest value is less than 5):

Date Time ID Value
2/4/2015 17:25 252 6.8
2/5/2015 16:23 252 5.5
2/5/2015 16:25 252 4.3

Step two: true values should carry the entire column of data (just the true column of data, not the false ones) to the adjacent sheet

Any help is greatly appreciated

Also there are some rows where only one ID data set exists, in that case, they only need to be filtered for being true or false, there does not need to be a comparison of duplicates
 
Upvote 0
Hi, tournapart
Welcome to the MrExcel!

You responded to an older thread; your chances to get response are reduced. i''ve currently no time to take a look at your request. You would better start your own thread; you can refer to this one if you want.

kind regards,
Erik
 
Upvote 0
Hello,
I have a workbook and I am trying to cut and paste all the data in column A (including whole row), to sheet 2, my criteria is that all data must be over 6 digits.
Can you please help me.
I have attached the file .
Cheers


Product IDProduct NameAverage Overall
Rating
Total Submitted
Reviews
% Approved% Rejected% Pending% 5-Star% 4-Star% 3-Star% 2-Star% 1-Star
964726Halfords 9v Battery 5 Pack5.001100%0%0%100%
966077Castrol Power 1 4T 10W/30 Motorcycle Engine Oil - 1ltr5.0014100%0%0%100%
641225Clarks CP501 V-Brake Block Insert5.001100%0%0%100%
364562Halfords Advanced Impact Socket 30mm 1/2" Drive5.002100%0%0%100%

<colgroup><col><col><col><col><col><col><col><col span="5"></colgroup><tbody>
</tbody>
1472659270965Tog24 Zenon Mens Down Hooded Jacket Navy1.0010%100%0%100%
1472659220621Thh Ts-80 Plain Full Face Motorcycle Helmet S Matt Black1.0010%100%0%100%
1472659220991Spyke Sp004 Owl Wp Motorcycle Boots 42 Black (uk 8)1.0010%100%0%100%
1472659220994Spyke Sp004 Owl Wp Motorcycle Boots 45 Black (uk 11)1.0010%100%0%100%
14726592223505131-0104 - Black Beacon Waterproof Motorcycle Rainsuit S Black (d-002)1.0010%100%0%100%

<colgroup><col><col><col><col><col><col><col><col span="5"></colgroup><tbody>
</tbody>
 
Upvote 0
elsa2583,

Welcome to the MrExcel forum.


We can not tell where your raw data is located, sheet name, cells, cell formatting, rows, columns, and, we can not tell where the results should be, sheet name, cells, cell formatting, rows, columns.


We would like more information. Please see the Forum Use Guidelines in the following link:

http://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html


See reply #2 at the next link, if you want to show small screenshots, of the raw data, and, what the results should look like.

http://www.mrexcel.com/forum/about-board/508133-attachments.html#post2507729


Or, you can post your workbook/worksheets to the following free site (sensitive data changed), mark the workbook for sharing, and, provide us with a link to your workbook:

https://dropbox.com
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top