Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to sort data?

Sheet to be copied to is Sheet2, sheet with data is Sheet1.


Dim rngYr as Range, rngDay as Range
Dim rng as Range, rngB as Range, rng1 as Range
Dim sAddr as String
With Worksheets("Sheet2")
set rngB = .range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each rngYr in rngB
if not isempty(rngYr) then
set rngDay = rngYr.offset(0,2)
With Worksheets("Sheet1")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End with

set rng1 = rng.find(rngYr.Value)
if not rng1 is nothing then
sAddr = rng1.Addr
do
if rng1.offset(0,2).Value = rngDay.Value
rng1.offset(0,3).Resize(12,5).copy _
Destination:=rngDay.offset(0,1)
exit do
end if
set rng1 = rng.findnext(rng1)
loop while rng1.address < sAddr
End if
Next

Code is untested and may contain typos

--
Regards,
Tom Ogilvy


"KiriumF1" wrote in message
...
hi i have data in this form
Year Month Day of year, n DataA DataB DataC DataD DataE
97 Oct 291 111 222 333 444 555
666 777 888 999 000
97 Dec 350 123 345 456 234 456
321 232 543 432 246
654 332 569 432 234

Actually each year and month data has 12 rows each ( the example above has

2
rows and 3 rows as an example)

I would like to sort this data into another spreadsheet which already has
the data fields

Year Month Day of Year,n DataA DataB DataC DataD
96 Oct 298
... ... ...
... ... ...

How do i write a VBA program to search for the data in the first

spreadsheet
based on the year and day_of_year, n , and copy and paste the

corresponding
data to the second spreadsheet accordingly?

If i am unclear, basically, if the first field in the second spreadsheet

was
96 and 298, the program will search the first spreadsheet based on 96 and
298, copy the corresponding data from 12 rows of the data fields

DataA,DataB,
DataC, etc and paste this data onto the second spreadsheet at the rows

with
96 and 298, and so on.

Sorry if it's confusing! Thanks if someone can help me on this!




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default how to sort data?

Hi thanks for your Help! But there's a slight problem, i couldn't run it as
there's an error, "Compile Error: Next without For"

I checked and dun think there's a problem, cos you used For Each and it
ended with Next. Could you advise me on this? Thanks!

"Tom Ogilvy" wrote:

Sheet to be copied to is Sheet2, sheet with data is Sheet1.


Dim rngYr as Range, rngDay as Range
Dim rng as Range, rngB as Range, rng1 as Range
Dim sAddr as String
With Worksheets("Sheet2")
set rngB = .range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each rngYr in rngB
if not isempty(rngYr) then
set rngDay = rngYr.offset(0,2)
With Worksheets("Sheet1")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End with

set rng1 = rng.find(rngYr.Value)
if not rng1 is nothing then
sAddr = rng1.Addr
do
if rng1.offset(0,2).Value = rngDay.Value
rng1.offset(0,3).Resize(12,5).copy _
Destination:=rngDay.offset(0,1)
exit do
end if
set rng1 = rng.findnext(rng1)
loop while rng1.address < sAddr
End if
Next

Code is untested and may contain typos

--
Regards,
Tom Ogilvy


"KiriumF1" wrote in message
...
hi i have data in this form
Year Month Day of year, n DataA DataB DataC DataD DataE
97 Oct 291 111 222 333 444 555
666 777 888 999 000
97 Dec 350 123 345 456 234 456
321 232 543 432 246
654 332 569 432 234

Actually each year and month data has 12 rows each ( the example above has

2
rows and 3 rows as an example)

I would like to sort this data into another spreadsheet which already has
the data fields

Year Month Day of Year,n DataA DataB DataC DataD
96 Oct 298
... ... ...
... ... ...

How do i write a VBA program to search for the data in the first

spreadsheet
based on the year and day_of_year, n , and copy and paste the

corresponding
data to the second spreadsheet accordingly?

If i am unclear, basically, if the first field in the second spreadsheet

was
96 and 298, the program will search the first spreadsheet based on 96 and
298, copy the corresponding data from 12 rows of the data fields

DataA,DataB,
DataC, etc and paste this data onto the second spreadsheet at the rows

with
96 and 298, and so on.

Sorry if it's confusing! Thanks if someone can help me on this!





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to sort data?

This worked for me (based on what I interpret your sheets to look like).

Sub Tester1()
Dim rngYr As Range, rngDay As Range
Dim rng As Range, rngB As Range, rng1 As Range
Dim sAddr As String
With Worksheets("Sheet2")
Set rngB = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With
For Each rngYr In rngB
If Not IsEmpty(rngYr) Then
Set rngDay = rngYr.Offset(0, 2)
With Worksheets("Sheet1")
Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With

Set rng1 = rng.Find(rngYr.Value)
If Not rng1 Is Nothing Then
sAddr = rng1.Address
Do
If rng1.Offset(0, 2).Value = rngDay.Value Then
rng1.Offset(0, 3).Resize(12, 5).Copy _
Destination:=rngDay.Offset(0, 1)
Exit Do
End If
Set rng1 = rng.FindNext(rng1)
Loop While rng1.Address < sAddr
End If
End If
Next


End Sub

--
Regards,
Tom Ogilvy

"KiriumF1" wrote in message
...
Hi thanks for your Help! But there's a slight problem, i couldn't run it

as
there's an error, "Compile Error: Next without For"

I checked and dun think there's a problem, cos you used For Each and it
ended with Next. Could you advise me on this? Thanks!

"Tom Ogilvy" wrote:

Sheet to be copied to is Sheet2, sheet with data is Sheet1.


Dim rngYr as Range, rngDay as Range
Dim rng as Range, rngB as Range, rng1 as Range
Dim sAddr as String
With Worksheets("Sheet2")
set rngB = .range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each rngYr in rngB
if not isempty(rngYr) then
set rngDay = rngYr.offset(0,2)
With Worksheets("Sheet1")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End with

set rng1 = rng.find(rngYr.Value)
if not rng1 is nothing then
sAddr = rng1.Addr
do
if rng1.offset(0,2).Value = rngDay.Value
rng1.offset(0,3).Resize(12,5).copy _
Destination:=rngDay.offset(0,1)
exit do
end if
set rng1 = rng.findnext(rng1)
loop while rng1.address < sAddr
End if
Next

Code is untested and may contain typos

--
Regards,
Tom Ogilvy


"KiriumF1" wrote in message
...
hi i have data in this form
Year Month Day of year, n DataA DataB DataC DataD DataE
97 Oct 291 111 222 333 444 555
666 777 888 999 000
97 Dec 350 123 345 456 234 456
321 232 543 432 246
654 332 569 432 234

Actually each year and month data has 12 rows each ( the example above

has
2
rows and 3 rows as an example)

I would like to sort this data into another spreadsheet which already

has
the data fields

Year Month Day of Year,n DataA DataB DataC DataD
96 Oct 298
... ... ...
... ... ...

How do i write a VBA program to search for the data in the first

spreadsheet
based on the year and day_of_year, n , and copy and paste the

corresponding
data to the second spreadsheet accordingly?

If i am unclear, basically, if the first field in the second

spreadsheet
was
96 and 298, the program will search the first spreadsheet based on 96

and
298, copy the corresponding data from 12 rows of the data fields

DataA,DataB,
DataC, etc and paste this data onto the second spreadsheet at the rows

with
96 and 298, and so on.

Sorry if it's confusing! Thanks if someone can help me on this!







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default how to sort data?

Try the following:

Dim rngYr As Range, rngDay As Range
Dim rng As Range, rngB As Range, rng1 As Range
Dim sAddr As String
With Worksheets("Sheet2")
Set rngB = .Range(.Cells(1, 1), .Cells(Rows.Count,
1).End(xlUp))
End With
For Each rngYr In rngB
If Not IsEmpty(rngYr) Then
Set rngDay = rngYr.Offset(0, 2)
With Worksheets("Sheet1")
Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count,
1).End(xlUp))
End With

Set rng1 = rng.Find(rngYr.Value)
If Not rng1 Is Nothing Then
sAddr = rng1.Addr
Do
If rng1.Offset(0, 2).Value = rngDay.Value Then
rng1.Offset(0, 3).Resize(12, 5).Copy _
Destination:=rngDay.Offset(0, 1)
Exit Do
End If
Set rng1 = rng.FindNext(rng1)
Loop While rng1.Address < sAddr
End If
End If
Next rngYr



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"KiriumF1" wrote in message
...
Hi thanks for your Help! But there's a slight problem, i
couldn't run it as
there's an error, "Compile Error: Next without For"

I checked and dun think there's a problem, cos you used For
Each and it
ended with Next. Could you advise me on this? Thanks!

"Tom Ogilvy" wrote:

Sheet to be copied to is Sheet2, sheet with data is Sheet1.


Dim rngYr as Range, rngDay as Range
Dim rng as Range, rngB as Range, rng1 as Range
Dim sAddr as String
With Worksheets("Sheet2")
set rngB =
.range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each rngYr in rngB
if not isempty(rngYr) then
set rngDay = rngYr.offset(0,2)
With Worksheets("Sheet1")
set rng =
.Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End with

set rng1 = rng.find(rngYr.Value)
if not rng1 is nothing then
sAddr = rng1.Addr
do
if rng1.offset(0,2).Value = rngDay.Value
rng1.offset(0,3).Resize(12,5).copy _
Destination:=rngDay.offset(0,1)
exit do
end if
set rng1 = rng.findnext(rng1)
loop while rng1.address < sAddr
End if
Next

Code is untested and may contain typos

--
Regards,
Tom Ogilvy


"KiriumF1" wrote in
message
...
hi i have data in this form
Year Month Day of year, n DataA DataB DataC DataD DataE
97 Oct 291 111 222 333 444 555
666 777 888 999 000
97 Dec 350 123 345 456 234 456
321 232 543 432 246
654 332 569 432 234

Actually each year and month data has 12 rows each ( the
example above has

2
rows and 3 rows as an example)

I would like to sort this data into another spreadsheet
which already has
the data fields

Year Month Day of Year,n DataA DataB DataC DataD
96 Oct 298
... ... ...
... ... ...

How do i write a VBA program to search for the data in the
first

spreadsheet
based on the year and day_of_year, n , and copy and paste
the

corresponding
data to the second spreadsheet accordingly?

If i am unclear, basically, if the first field in the second
spreadsheet

was
96 and 298, the program will search the first spreadsheet
based on 96 and
298, copy the corresponding data from 12 rows of the data
fields

DataA,DataB,
DataC, etc and paste this data onto the second spreadsheet
at the rows

with
96 and 298, and so on.

Sorry if it's confusing! Thanks if someone can help me on
this!







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default how to sort data?

Thanks! Works like a charm!

"Tom Ogilvy" wrote:

This worked for me (based on what I interpret your sheets to look like).

Sub Tester1()
Dim rngYr As Range, rngDay As Range
Dim rng As Range, rngB As Range, rng1 As Range
Dim sAddr As String
With Worksheets("Sheet2")
Set rngB = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With
For Each rngYr In rngB
If Not IsEmpty(rngYr) Then
Set rngDay = rngYr.Offset(0, 2)
With Worksheets("Sheet1")
Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With

Set rng1 = rng.Find(rngYr.Value)
If Not rng1 Is Nothing Then
sAddr = rng1.Address
Do
If rng1.Offset(0, 2).Value = rngDay.Value Then
rng1.Offset(0, 3).Resize(12, 5).Copy _
Destination:=rngDay.Offset(0, 1)
Exit Do
End If
Set rng1 = rng.FindNext(rng1)
Loop While rng1.Address < sAddr
End If
End If
Next


End Sub

--
Regards,
Tom Ogilvy

"KiriumF1" wrote in message
...
Hi thanks for your Help! But there's a slight problem, i couldn't run it

as
there's an error, "Compile Error: Next without For"

I checked and dun think there's a problem, cos you used For Each and it
ended with Next. Could you advise me on this? Thanks!

"Tom Ogilvy" wrote:

Sheet to be copied to is Sheet2, sheet with data is Sheet1.


Dim rngYr as Range, rngDay as Range
Dim rng as Range, rngB as Range, rng1 as Range
Dim sAddr as String
With Worksheets("Sheet2")
set rngB = .range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each rngYr in rngB
if not isempty(rngYr) then
set rngDay = rngYr.offset(0,2)
With Worksheets("Sheet1")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End with

set rng1 = rng.find(rngYr.Value)
if not rng1 is nothing then
sAddr = rng1.Addr
do
if rng1.offset(0,2).Value = rngDay.Value
rng1.offset(0,3).Resize(12,5).copy _
Destination:=rngDay.offset(0,1)
exit do
end if
set rng1 = rng.findnext(rng1)
loop while rng1.address < sAddr
End if
Next

Code is untested and may contain typos

--
Regards,
Tom Ogilvy


"KiriumF1" wrote in message
...
hi i have data in this form
Year Month Day of year, n DataA DataB DataC DataD DataE
97 Oct 291 111 222 333 444 555
666 777 888 999 000
97 Dec 350 123 345 456 234 456
321 232 543 432 246
654 332 569 432 234

Actually each year and month data has 12 rows each ( the example above

has
2
rows and 3 rows as an example)

I would like to sort this data into another spreadsheet which already

has
the data fields

Year Month Day of Year,n DataA DataB DataC DataD
96 Oct 298
... ... ...
... ... ...

How do i write a VBA program to search for the data in the first
spreadsheet
based on the year and day_of_year, n , and copy and paste the
corresponding
data to the second spreadsheet accordingly?

If i am unclear, basically, if the first field in the second

spreadsheet
was
96 and 298, the program will search the first spreadsheet based on 96

and
298, copy the corresponding data from 12 rows of the data fields
DataA,DataB,
DataC, etc and paste this data onto the second spreadsheet at the rows
with
96 and 298, and so on.

Sorry if it's confusing! Thanks if someone can help me on this!










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default how to sort data?

Thanks! Works like a charm too!

"Chip Pearson" wrote:

Try the following:

Dim rngYr As Range, rngDay As Range
Dim rng As Range, rngB As Range, rng1 As Range
Dim sAddr As String
With Worksheets("Sheet2")
Set rngB = .Range(.Cells(1, 1), .Cells(Rows.Count,
1).End(xlUp))
End With
For Each rngYr In rngB
If Not IsEmpty(rngYr) Then
Set rngDay = rngYr.Offset(0, 2)
With Worksheets("Sheet1")
Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count,
1).End(xlUp))
End With

Set rng1 = rng.Find(rngYr.Value)
If Not rng1 Is Nothing Then
sAddr = rng1.Addr
Do
If rng1.Offset(0, 2).Value = rngDay.Value Then
rng1.Offset(0, 3).Resize(12, 5).Copy _
Destination:=rngDay.Offset(0, 1)
Exit Do
End If
Set rng1 = rng.FindNext(rng1)
Loop While rng1.Address < sAddr
End If
End If
Next rngYr



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"KiriumF1" wrote in message
...
Hi thanks for your Help! But there's a slight problem, i
couldn't run it as
there's an error, "Compile Error: Next without For"

I checked and dun think there's a problem, cos you used For
Each and it
ended with Next. Could you advise me on this? Thanks!

"Tom Ogilvy" wrote:

Sheet to be copied to is Sheet2, sheet with data is Sheet1.


Dim rngYr as Range, rngDay as Range
Dim rng as Range, rngB as Range, rng1 as Range
Dim sAddr as String
With Worksheets("Sheet2")
set rngB =
.range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End With
for each rngYr in rngB
if not isempty(rngYr) then
set rngDay = rngYr.offset(0,2)
With Worksheets("Sheet1")
set rng =
.Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
End with

set rng1 = rng.find(rngYr.Value)
if not rng1 is nothing then
sAddr = rng1.Addr
do
if rng1.offset(0,2).Value = rngDay.Value
rng1.offset(0,3).Resize(12,5).copy _
Destination:=rngDay.offset(0,1)
exit do
end if
set rng1 = rng.findnext(rng1)
loop while rng1.address < sAddr
End if
Next

Code is untested and may contain typos

--
Regards,
Tom Ogilvy


"KiriumF1" wrote in
message
...
hi i have data in this form
Year Month Day of year, n DataA DataB DataC DataD DataE
97 Oct 291 111 222 333 444 555
666 777 888 999 000
97 Dec 350 123 345 456 234 456
321 232 543 432 246
654 332 569 432 234

Actually each year and month data has 12 rows each ( the
example above has
2
rows and 3 rows as an example)

I would like to sort this data into another spreadsheet
which already has
the data fields

Year Month Day of Year,n DataA DataB DataC DataD
96 Oct 298
... ... ...
... ... ...

How do i write a VBA program to search for the data in the
first
spreadsheet
based on the year and day_of_year, n , and copy and paste
the
corresponding
data to the second spreadsheet accordingly?

If i am unclear, basically, if the first field in the second
spreadsheet
was
96 and 298, the program will search the first spreadsheet
based on 96 and
298, copy the corresponding data from 12 rows of the data
fields
DataA,DataB,
DataC, etc and paste this data onto the second spreadsheet
at the rows
with
96 and 298, and so on.

Sorry if it's confusing! Thanks if someone can help me on
this!








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
data, sort option is grayed. how to sort on a column? Steve Richter Excel Discussion (Misc queries) 1 September 25th 07 03:25 PM
Help to sort out filtered data from the data contained in another sheet of the same workbook No News Excel Worksheet Functions 1 July 28th 06 04:04 PM
I want to convert word column data to excel row data to sort addre craywill Excel Discussion (Misc queries) 0 April 18th 06 07:16 PM
data sort is not including all columns in sort Tracy Excel Discussion (Misc queries) 1 October 4th 05 12:16 AM
How do I sort a column of data and have each data row sort accordi Oedalis Excel Discussion (Misc queries) 1 March 17th 05 11:52 PM


All times are GMT +1. The time now is 05:26 PM.

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

About Us

"It's about Microsoft Excel"