PC Review


Reply
Thread Tools Rate Thread

Condition based copy/paste of range

 
 
nitn28@gmail.com
Guest
Posts: n/a
 
      28th Apr 2007
hello everyone

i m learning alot from this group
i need direction to solve this problm, which i m trying hard but not
able to write xact vba code/macro bcoz m novice

i hav data in two columns

a b

1(x1) 2(y1)
3(x2) 4(y2)
5 6
7 8
9 10
16 17
18 19
20 21
25 27

i want to calucate distance between two sets of data which are in
column "a" and "b"

d = sqrt((x2-x1)^2+(y2-y1)^2))

and if d is >=4 or <=-4 then

data set should be copied to next columns wherever this condition not
satisfied

for eg

a b c d e
f

a1 b1 a1 b1 a6 b6
a2 b2 a2 b2 a7 b7
a3 b3 a3 b3 a8 b8
a4 b4 a4 b4
a5 b5 a5 b5
a6 b6
a7 b7
a8 b8
a9 b9


in above example i tried to show dat from a1:b5 ( "d" is less than 4
so copied in column "c" and "d" ,

but value of "d " is .> 4 for "a6,b6 & a5,b5"
so copied in next colmn til difference is less than 4
and like wise a9,b9 in next columns

hop i hav made my problm bit clear

hop i wil get some suggestions to write a code
witing for ur replys
many thanx in advance
4 ur time n efort

 
Reply With Quote
 
 
 
 
New Member
Join Date: Apr 2007
Posts: 6
 
      28th Apr 2007
sorry evryone

actually its all messedup all format of my querry
in this forum when i post it

plz chk this forum .....microsoft . public . excel . programming
wher i hav posted d sam thread n help me out plz if u find time
 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      28th Apr 2007
I'm going to assume that your data is in columns A and B and you have a
header in the first row.

I don't think this is exactly what you want, but you're going to have to
tell us what needs to be changed. You may be able to figure out your code
from here.

Sub test()

Dim myRange As Range
Dim r As Range
Dim d As Variant

Set myRange = Cells(3, 1)
lrow = Cells(Rows.Count, myRange.Column).End(xlUp).Row
Set myRange = myRange.Resize(lrow, 1)

For Each r In myRange
d = Sqr((r.Value - r.Offset(-1, 0).Value) ^ 2 + (r.Offset(0, 1).Value -
r.Offset(-1, 1).Value) ^ 2)
Debug.Print r.Address, d
If Abs(d) < 4 Then
r.Offset(0, 2).Value = r.Value
r.Offset(0, 3).Value = r.Offset(0, 1).Value
End If
Next r

End Sub


"(E-Mail Removed)" wrote:

> hello everyone
>
> i m learning alot from this group
> i need direction to solve this problm, which i m trying hard but not
> able to write xact vba code/macro bcoz m novice
>
> i hav data in two columns
>
> a b
>
> 1(x1) 2(y1)
> 3(x2) 4(y2)
> 5 6
> 7 8
> 9 10
> 16 17
> 18 19
> 20 21
> 25 27
>
> i want to calucate distance between two sets of data which are in
> column "a" and "b"
>
> d = sqrt((x2-x1)^2+(y2-y1)^2))
>
> and if d is >=4 or <=-4 then
>
> data set should be copied to next columns wherever this condition not
> satisfied
>
> for eg
>
> a b c d e
> f
>
> a1 b1 a1 b1 a6 b6
> a2 b2 a2 b2 a7 b7
> a3 b3 a3 b3 a8 b8
> a4 b4 a4 b4
> a5 b5 a5 b5
> a6 b6
> a7 b7
> a8 b8
> a9 b9
>
>
> in above example i tried to show dat from a1:b5 ( "d" is less than 4
> so copied in column "c" and "d" ,
>
> but value of "d " is .> 4 for "a6,b6 & a5,b5"
> so copied in next colmn til difference is less than 4
> and like wise a9,b9 in next columns
>
> hop i hav made my problm bit clear
>
> hop i wil get some suggestions to write a code
> witing for ur replys
> many thanx in advance
> 4 ur time n efort
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to copy and paste based on a condition kathryn462 Microsoft Excel Misc 5 14th Oct 2008 12:59 AM
Copy and Paste based on Condition =?Utf-8?B?RUo=?= Microsoft Excel Misc 1 27th Jun 2007 11:17 PM
Condition based copy/paste of range nitn28@gmail.com Microsoft Excel Programming 1 27th Apr 2007 12:44 PM
Condition based copy/paste of range nitn28@gmail.com Microsoft Excel Programming 0 27th Apr 2007 05:48 AM
Copy range based on condition =?Utf-8?B?U290b21heW9y?= Microsoft Excel Programming 1 10th Sep 2006 01:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:28 AM.