Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Condition based copy/paste of range

Hello everyone

I am new to excel vba n stucked in a problem hop i wil get help form
this forum

i hav around 2000 data in my worksheet n need to sort it out

My data is like this

1 2
3 4
5 6
7 8
9 10
13 15
15 16
17 19
19 21
28 27

as shown above i hav data in two columns wat i want to do is to copy
and paste the above values in different column based on condition say
in coulm c,d, e,f

Condition is if cell(2,1)-cell(1,1) and cell( 2,1)- cell( 2,2)
[subtraction]
3 or < -3 then copy the value of cell(2,1)&cell(1,1) in col c & col d exit for


move to next row if condition is not true then copy the range

just like this
a b c d e f g h
1 2 1 2 13 15 28 27
3 4 3 4 17 19
5 6 5 6 19 21
7 8 7 8 [these values r in
9 10 9 10 diff col. bn 13 &9,
13 15 10&15 is grtr than 3
15 16
17 19 [copied d above range
19 21 bcoz deiff is less than 3 ]
28 27

Hope sum of u get time time to help me put as i m begnr in it n trying
hard to xplore xcel - vba

many thanx

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Condition based copy/paste of range

it was hard to understnad your requirements. I tried my best. This may work

Sub BinPairs()

'Let first row contain header data containing range of data in column
'Real data starts in row 2
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'columns are in pairs, so subtract 1
'subtract another 2 for last two columns
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column - 3

Set SortDataRange = Range(Cells(2, "A"), Cells(LastRow, "A"))


For Each cell In SortDataRange

'Put data in last column if doesn't fit into other columns
Inserted = False
For ColumnCount = 3 To LastCol Step 2


If (cell = Cells(1, ColumnCount)) And _
(cell < Cells(1, ColumnCount + 2)) And _
(cell.Offset(rowoffset:=0, columnoffset:=1) = _
Cells(1, ColumnCount + 1)) And _
(cell.Offset(rowoffset:=0, columnoffset:=1) < _
Cells(1, ColumnCount + 3)) Then

Inserted = True
'findlast cell in column and insert afterwards
LastRow = Cells(Rows.Count, ColumnCount).End(xlUp).Row
Cells(LastRow + 1, ColumnCount) = cell
Cells(LastRow + 1, ColumnCount + 1) = _
cell.Offset(rowoffset:=0, columnoffset:=1)
Exit For
End If

Next ColumnCount

If Inserted = False Then
'findlast cell in column and insert afterwards
LastRow = Cells(Rows.Count, ColumnCount).End(xlUp).Row
Cells(LastRow + 1, ColumnCount + 2) = cell
Cells(LastRow + 1, ColumnCount + 3) = _
cell.Offset(rowoffset:=0, columnoffset:=1)
End If

Next cell


End Sub


" wrote:

Hello everyone

I am new to excel vba n stucked in a problem hop i wil get help form
this forum

i hav around 2000 data in my worksheet n need to sort it out

My data is like this

1 2
3 4
5 6
7 8
9 10
13 15
15 16
17 19
19 21
28 27

as shown above i hav data in two columns wat i want to do is to copy
and paste the above values in different column based on condition say
in coulm c,d, e,f

Condition is if cell(2,1)-cell(1,1) and cell( 2,1)- cell( 2,2)
[subtraction]
3 or < -3 then copy the value of cell(2,1)&cell(1,1) in col c & col d exit for


move to next row if condition is not true then copy the range

just like this
a b c d e f g h
1 2 1 2 13 15 28 27
3 4 3 4 17 19
5 6 5 6 19 21
7 8 7 8 [these values r in
9 10 9 10 diff col. bn 13 &9,
13 15 10&15 is grtr than 3
15 16
17 19 [copied d above range
19 21 bcoz deiff is less than 3 ]
28 27

Hope sum of u get time time to help me put as i m begnr in it n trying
hard to xplore xcel - vba

many thanx


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
macro to copy and paste based on a condition kathryn462 Excel Discussion (Misc queries) 5 October 14th 08 12:59 AM
Copy and Paste based on Condition EJ Excel Discussion (Misc queries) 1 June 27th 07 11:17 PM
Condition based copy/paste of range [email protected] Excel Programming 0 April 27th 07 05:48 AM
Copy range based on condition Sotomayor Excel Programming 1 September 10th 06 01:11 AM
How to copy only some rows from range based on condition? [email protected][_2_] Excel Programming 2 January 30th 06 01:04 AM


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