Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trouble sorting data by cell value


Hi,

I am having trouble writing a macro. I need to search the data i
'Sheet2' and sort the data by value into separate worksheets. So i
column A if the value of a cell is 9 the data will be pasted int
Worksheet'9-10', if the value of a cell is 10, the data will be paste
into Worksheet'10-11' and so on...

This is the macro i have so far which will not work;
Sub STEP3()
Dim rng As Range, cell As Range, sel As Range
Set rng = Intersect(Range("A:A"), Sheets("Sheet2").UsedRange)
For Each cell In rng
If (cell.Value) = "9" Then
sel.EntireRow.Select
Application.CutCopyMode = False
Selection.Copy
Sheets("9-10").Select
Range("A3").Select
ActiveSheet.Paste
If (cell.Value) = "10" Then
sel.EntireRow.Select
Application.CutCopyMode = False
Selection.Copy
Sheets("10-11").Select
Range("A3").Select
ActiveSheet.Paste
If sel Is Nothing Then
Set sel = cell
Else: Set sel = Union(sel, cell)
On Error Resume Next
End If
End If
End If
Next
End Sub

Please can you help, Many thanks,
Andre

--
Shandy72
-----------------------------------------------------------------------
Shandy720's Profile: http://www.excelforum.com/member.php...fo&userid=2623
View this thread: http://www.excelforum.com/showthread.php?threadid=39526

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Trouble sorting data by cell value

Can you explain what is happening - where it is going wrong? Do you get an
error message? If not, what is different from the way the macro behaves and
the way you want it to behave?
--
- K Dales


"Shandy720" wrote:


Hi,

I am having trouble writing a macro. I need to search the data in
'Sheet2' and sort the data by value into separate worksheets. So in
column A if the value of a cell is 9 the data will be pasted into
Worksheet'9-10', if the value of a cell is 10, the data will be pasted
into Worksheet'10-11' and so on...

This is the macro i have so far which will not work;
Sub STEP3()
Dim rng As Range, cell As Range, sel As Range
Set rng = Intersect(Range("A:A"), Sheets("Sheet2").UsedRange)
For Each cell In rng
If (cell.Value) = "9" Then
sel.EntireRow.Select
Application.CutCopyMode = False
Selection.Copy
Sheets("9-10").Select
Range("A3").Select
ActiveSheet.Paste
If (cell.Value) = "10" Then
sel.EntireRow.Select
Application.CutCopyMode = False
Selection.Copy
Sheets("10-11").Select
Range("A3").Select
ActiveSheet.Paste
If sel Is Nothing Then
Set sel = cell
Else: Set sel = Union(sel, cell)
On Error Resume Next
End If
End If
End If
Next
End Sub

Please can you help, Many thanks,
Andrew


--
Shandy720
------------------------------------------------------------------------
Shandy720's Profile: http://www.excelforum.com/member.php...o&userid=26230
View this thread: http://www.excelforum.com/showthread...hreadid=395266


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trouble sorting data by cell value


I now get the error message
Runtime error '1004'
'Intersect' of Object '_Global' faile

--
Shandy72
-----------------------------------------------------------------------
Shandy720's Profile: http://www.excelforum.com/member.php...fo&userid=2623
View this thread: http://www.excelforum.com/showthread.php?threadid=39526

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trouble sorting data by cell value


I have a sheet of data in five columns which i need to organise into
different worksheets. So i need a macro to check all cellvalues in
ColumnA (which range from 9-20) and copy the entire row into a separate
worksheet for each value.
In the ned i want a worksheet with all the rows which have '9' in
ColumnA, a worksheet which has all the rows with '10' in ColumnA and so
on.

Any help would be great, thanks a lot,
Andrew


--
Shandy720
------------------------------------------------------------------------
Shandy720's Profile: http://www.excelforum.com/member.php...o&userid=26230
View this thread: http://www.excelforum.com/showthread...hreadid=395266

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trouble sorting data by cell value

Try looking here at Ron de Bruin's site:

http://www.rondebruin.nl/copy5.htm

--
Regards,
Tom Ogilvy


"Shandy720" wrote
in message ...

I have a sheet of data in five columns which i need to organise into
different worksheets. So i need a macro to check all cellvalues in
ColumnA (which range from 9-20) and copy the entire row into a separate
worksheet for each value.
In the ned i want a worksheet with all the rows which have '9' in
ColumnA, a worksheet which has all the rows with '10' in ColumnA and so
on.

Any help would be great, thanks a lot,
Andrew


--
Shandy720
------------------------------------------------------------------------
Shandy720's Profile:

http://www.excelforum.com/member.php...o&userid=26230
View this thread: http://www.excelforum.com/showthread...hreadid=395266





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 296
Default Trouble sorting data by cell value

It sounds as if you need to filter the database. Either in place or by
extracting records according to a varying criteria and listing them
elsewhere.

Try recording a [Data Filter Advanced Filter] macro, see what the
result is and modify accordingly. Adding a loop perhaps to the macro
to modify the selection criteria.

Rgds


On Fri, 12 Aug 2005 07:52:43 -0500, Shandy720
wrote:


I have a sheet of data in five columns which i need to organise into
different worksheets. So i need a macro to check all cellvalues in
ColumnA (which range from 9-20) and copy the entire row into a separate
worksheet for each value.
In the ned i want a worksheet with all the rows which have '9' in
ColumnA, a worksheet which has all the rows with '10' in ColumnA and so
on.

Any help would be great, thanks a lot,
Andrew


__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________
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
Trouble Sorting Spreadsheet Susan Excel Worksheet Functions 1 May 23rd 07 02:50 PM
Sorting trouble orpheusgrey Excel Discussion (Misc queries) 2 March 9th 07 01:10 PM
Trouble with sorting and Worksheet protect Eileen Excel Discussion (Misc queries) 3 January 24th 07 05:22 PM
Trouble with Sorting Hyperlinks Jim S Excel Discussion (Misc queries) 1 October 18th 06 10:18 PM
Trouble sorting linked worksheet - need help [email protected] Excel Discussion (Misc queries) 2 December 5th 05 09:39 PM


All times are GMT +1. The time now is 04:19 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"