 |
12-05-2011, 11:51 AM
|
#1 (permalink)
|
|
In The Zone
Join Date: Feb 2008
Location: New Delhi
Posts: 212
|
need logic in vba
i need the logic in vba(using any loops) for this >
if col A has repeted vales then col B should have the first instance value for such repetations as x and rest as y. basically i need to populate col B in this way, col A is only present.
eg,
A B
2 x
2 y
1 y
3 x
3 y
3 y
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
12-05-2011, 12:04 PM
|
#2 (permalink)
|
|
Super Moderator
Join Date: May 2008
Location: New Delhi
Posts: 5,548
|
Re: need logic in vba
^^
The first instance of 2 = x, for 1 = y, how can 3 = y again.
Give me the logic more clear, will help.
__________________
MSI P45 Platinum(BIOS v1.7B)|Q9550[E0]@3.85Ghz@1.320V[453x8.5]MCH@1.184V|ICH@1.55V|DDR_V_Ref_A_B@1.05V|NH-D14|Corsair TWIN2X4096-8500C5(5-5-5-15)@1089Mhz@2.14V
2xHD4890[Xfire]@1000/900[MEM/GPU]|Corsair 650TX|Seagate180GB+80GB+WD1TB|SONY-DVD-R|CM690|2x120mm Scythe Ultra Kaze|DELL S2409W|APC 1100VA|Scythe Kaze Server
Windows 7 Ultimate RTM - 64BIT|Catalyst 10.5 (8.14.10.0753) forced with RadeonPRO|PS3 160GB|Sony 40EX520|AC Ryan POHD Mini|APC 800VA|APC 800VA|D425KT|CM100 Elite|2TB WD|Acer D255
Test your spoiler tags before submitting
|
|
|
12-05-2011, 12:08 PM
|
#3 (permalink)
|
|
In The Zone
Join Date: Feb 2008
Location: New Delhi
Posts: 212
|
Re: need logic in vba
No its not that 2 = anything. Nothing is equal to anything. There are 2 columns A and B. Column A is already populated with the given numbers. some numbers are repeted like number 2 and 3. 2 is always repeted twice and 3 is repeted thrice. now i want x in column B , against the first instance of 2 or 3 and y against the rest of the instances. So i am filling column B.
its in vba (excel)
Thanks
|
|
|
12-05-2011, 12:16 PM
|
#4 (permalink)
|
|
Super Moderator
Join Date: May 2008
Location: New Delhi
Posts: 5,548
|
Re: need logic in vba
^^
But this logic will not apply to the first instance of '1'..?
Only for '2' and '3'.
__________________
MSI P45 Platinum(BIOS v1.7B)|Q9550[E0]@3.85Ghz@1.320V[453x8.5]MCH@1.184V|ICH@1.55V|DDR_V_Ref_A_B@1.05V|NH-D14|Corsair TWIN2X4096-8500C5(5-5-5-15)@1089Mhz@2.14V
2xHD4890[Xfire]@1000/900[MEM/GPU]|Corsair 650TX|Seagate180GB+80GB+WD1TB|SONY-DVD-R|CM690|2x120mm Scythe Ultra Kaze|DELL S2409W|APC 1100VA|Scythe Kaze Server
Windows 7 Ultimate RTM - 64BIT|Catalyst 10.5 (8.14.10.0753) forced with RadeonPRO|PS3 160GB|Sony 40EX520|AC Ryan POHD Mini|APC 800VA|APC 800VA|D425KT|CM100 Elite|2TB WD|Acer D255
Test your spoiler tags before submitting
|
|
|
12-05-2011, 12:20 PM
|
#5 (permalink)
|
|
In The Zone
Join Date: Feb 2008
Location: New Delhi
Posts: 212
|
Re: need logic in vba
ya.. actually the data in column A is like
1
2
2
1
1
1
1
3
3
3
1
1
2
2
1
2
2
1
1
3
3
3
1
1
1
3
3
3
1
2
2
like this.. so i need x against the 'first' instance of 2 and 3. getting y against 1 is easy as there is only one instance but having problem with 2 and 3. rest of the instances will have a y.
|
|
|
12-05-2011, 12:27 PM
|
#6 (permalink)
|
|
Fullbring
Join Date: Jan 2008
Location: Soul Society
Posts: 5,523
|
Re: need logic in vba
Quote:
Originally Posted by arian29
eg,
A B
2 x
2 y
1 y
3 x
3 y
3 y
|
I think the e.g is like this
A B
2 x
2 y
1 x
3 x
3 y
3 y
__________________
I'm the One you've been Waiting for...
|
|
|
12-05-2011, 12:30 PM
|
#7 (permalink)
|
|
In The Zone
Join Date: Feb 2008
Location: New Delhi
Posts: 212
|
Re: need logic in vba
you can have x or y against 1, dosent matter, prob is with 2 and 3.
|
|
|
12-05-2011, 01:46 PM
|
#8 (permalink)
|
|
Super Moderator
Join Date: May 2008
Location: New Delhi
Posts: 5,548
|
Re: need logic in vba
Would a formulaic approach work here......
I pasted the data from post number 5 on a range of D10 : D40.
Then I wrote this formula in E10:
=IF(COUNTIF($D$10 : D10,D10)=1,"x","y")
Once you type the last bracket, press CONTROL+SHIFT+ENTER, and the formula will get {} around it.
Now double click down..>!
__________________
MSI P45 Platinum(BIOS v1.7B)|Q9550[E0]@3.85Ghz@1.320V[453x8.5]MCH@1.184V|ICH@1.55V|DDR_V_Ref_A_B@1.05V|NH-D14|Corsair TWIN2X4096-8500C5(5-5-5-15)@1089Mhz@2.14V
2xHD4890[Xfire]@1000/900[MEM/GPU]|Corsair 650TX|Seagate180GB+80GB+WD1TB|SONY-DVD-R|CM690|2x120mm Scythe Ultra Kaze|DELL S2409W|APC 1100VA|Scythe Kaze Server
Windows 7 Ultimate RTM - 64BIT|Catalyst 10.5 (8.14.10.0753) forced with RadeonPRO|PS3 160GB|Sony 40EX520|AC Ryan POHD Mini|APC 800VA|APC 800VA|D425KT|CM100 Elite|2TB WD|Acer D255
Test your spoiler tags before submitting
|
|
|
12-05-2011, 02:44 PM
|
#9 (permalink)
|
|
In The Zone
Join Date: Feb 2008
Location: New Delhi
Posts: 212
|
Re: need logic in vba
no its not working..
|
|
|
12-05-2011, 03:08 PM
|
#10 (permalink)
|
|
Fullbring
Join Date: Jan 2008
Location: Soul Society
Posts: 5,523
|
Re: need logic in vba
Quote:
Originally Posted by arian29
you can have x or y against 1, dosent matter, prob is with 2 and 3.
|
sorry i m n00b in vba.But
the logic will be like this
consider range of column A is A1:A20 => output will be B1:B20
start from A1 -> store it in a temp variable
Read A2 cell value & compare it with the temp variable if = then put y else put x
this will go on till A20
temp variable will always store the previous cell value
__________________
I'm the One you've been Waiting for...
|
|
|
12-05-2011, 04:26 PM
|
#11 (permalink)
|
|
Wise Old Owl
Join Date: Sep 2009
Posts: 1,624
|
Re: need logic in vba
I don't think this logic will work...coz what happens if any of those numbers repeat in the sequence....e.g 1 2 2 2 3 3 3 1 1 1 2 2 2....correct me if I am wrong...the output for this sequence should be x x y y x y y y y y y y y ...right?
__________________
Core 2 duo E4500 2.2gHz , ASUS P5GCMX , 3GB Transcend , Corsair VX 550w, MSI R5770 HAWK Edition 1GB, CM HAF-922, LG W2243T 21.5" LCD, I-Ball Baton
|
|
|
12-05-2011, 04:53 PM
|
#12 (permalink)
|
|
Super Moderator
Join Date: May 2008
Location: New Delhi
Posts: 5,548
|
Re: need logic in vba
Quote:
Originally Posted by arian29
no its not working..
|
Yes, because you did not follow the way I asked you to.
Quote:
Originally Posted by Zangetsu
sorry i m n00b in vba.But
the logic will be like this
consider range of column A is A1:A20 => output will be B1:B20
start from A1 -> store it in a temp variable
Read A2 cell value & compare it with the temp variable if = then put y else put x
this will go on till A20
temp variable will always store the previous cell value
|
There is absolutely no USE for VBA for this. VBA is used only when native excel cannot do the job.
Please see the sheet I have attached. Look at the yellow cells, and understand the formula I wrote. It is an array function, and does the job perfect.
Sample.xls - 4shared.com - online file sharing and storage - download
And I repeat again, there is no need to do this with VBA. It is shooting a fly with a cannon. Unless your data is crossing 50,000 rows or something.
__________________
MSI P45 Platinum(BIOS v1.7B)|Q9550[E0]@3.85Ghz@1.320V[453x8.5]MCH@1.184V|ICH@1.55V|DDR_V_Ref_A_B@1.05V|NH-D14|Corsair TWIN2X4096-8500C5(5-5-5-15)@1089Mhz@2.14V
2xHD4890[Xfire]@1000/900[MEM/GPU]|Corsair 650TX|Seagate180GB+80GB+WD1TB|SONY-DVD-R|CM690|2x120mm Scythe Ultra Kaze|DELL S2409W|APC 1100VA|Scythe Kaze Server
Windows 7 Ultimate RTM - 64BIT|Catalyst 10.5 (8.14.10.0753) forced with RadeonPRO|PS3 160GB|Sony 40EX520|AC Ryan POHD Mini|APC 800VA|APC 800VA|D425KT|CM100 Elite|2TB WD|Acer D255
Test your spoiler tags before submitting
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|