VBA code to find a cell containing certain word and using the row number of the cell run a if else statement.

ittan

New Member
Joined
Oct 23, 2013
Messages
37
[TABLE="width: 500"]
<tbody>[TR]
[TD]sl.no
[/TD]
[TD]customer ID
[/TD]
[TD]A gain target
[/TD]
[TD]A gain target Value
[/TD]
[TD]A loop target
[/TD]
[TD]A loop target value
[/TD]
[TD]A Loop high
[/TD]
[TD]A loop high value
[/TD]
[TD]B Gain target
[/TD]
[TD]B loop target
[/TD]
[TD]B loop high
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]345
[/TD]
[TD]345
[/TD]
[TD]1
[/TD]
[TD]345
[/TD]
[TD][/TD]
[TD]45
[/TD]
[TD][/TD]
[TD]34
[/TD]
[TD]45
[/TD]
[TD]67
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]234
[/TD]
[TD]3466
[/TD]
[TD]1
[/TD]
[TD]2345676
[/TD]
[TD]1
[/TD]
[TD]67
[/TD]
[TD]1
[/TD]
[TD]76
[/TD]
[TD]56
[/TD]
[TD]67
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]123
[/TD]
[TD]3457
[/TD]
[TD][/TD]
[TD]34567
[/TD]
[TD][/TD]
[TD]456
[/TD]
[TD]1
[/TD]
[TD]45
[/TD]
[TD]45
[/TD]
[TD]65
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]456
[/TD]
[TD]234
[/TD]
[TD]1
[/TD]
[TD]4554
[/TD]
[TD]1
[/TD]
[TD]798
[/TD]
[TD]1
[/TD]
[TD]43567
[/TD]
[TD]45
[/TD]
[TD]56
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]678
[/TD]
[TD]78
[/TD]
[TD][/TD]
[TD]43523
[/TD]
[TD][/TD]
[TD]345
[/TD]
[TD]1
[/TD]
[TD]45
[/TD]
[TD]564
[/TD]
[TD]45
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]789
[/TD]
[TD]345
[/TD]
[TD]1
[/TD]
[TD]3456
[/TD]
[TD]1
[/TD]
[TD]234
[/TD]
[TD]1
[/TD]
[TD]345
[/TD]
[TD]3423
[/TD]
[TD]233
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD]865
[/TD]
[TD]23
[/TD]
[TD][/TD]
[TD]674
[/TD]
[TD]1
[/TD]
[TD]67
[/TD]
[TD]1
[/TD]
[TD]65
[/TD]
[TD]34
[/TD]
[TD]34
[/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD]435
[/TD]
[TD]4
[/TD]
[TD]1
[/TD]
[TD]344
[/TD]
[TD]1
[/TD]
[TD]23
[/TD]
[TD]1
[/TD]
[TD]576
[/TD]
[TD]56
[/TD]
[TD]45
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 741"]
<tbody>[TR]
[TD]this is a sampe excell sheet only, number of rows and collumn is around 1000++. :P I was trying to create a program which will
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]look through the first row and search for a cell containing the word "target" and
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
if it find such a cell, it will run a 'if' condition. check if the value of the adjacent cell 'value' is 1 or 0, if it is 1 then it selects the value of "A gain target" if it is 0 it selects the value of "B gain target".

at the end it should come up with a excell sheet with only selected values, Serial no. and customer ID. and all the 'target value' at the end.

[TABLE="width: 500"]
<tbody>[TR]
[TD]sl.no
[/TD]
[TD]customer ID
[/TD]
[TD]gain target
[/TD]
[TD]loop target
[/TD]
[TD]gain target Value
[/TD]
[TD]loop target value
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]345
[/TD]
[TD]345
[/TD]
[TD]45
[/TD]
[TD]1
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]234
[/TD]
[TD]3466
[/TD]
[TD]2345676
[/TD]
[TD]1
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]123
[/TD]
[TD]45
[/TD]
[TD]45
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]456
[/TD]
[TD]234
[/TD]
[TD]4554
[/TD]
[TD]1
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]678
[/TD]
[TD]45
[/TD]
[TD]564
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]789
[/TD]
[TD]345
[/TD]
[TD]3456
[/TD]
[TD]1
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD]865
[/TD]
[TD]65
[/TD]
[TD]674
[/TD]
[TD][/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD]435
[/TD]
[TD]4
[/TD]
[TD]344
[/TD]
[TD]1
[/TD]
[TD]1
[/TD]
[/TR]
</tbody>[/TABLE]


thank you so much for your valuable responce, i'm very poor in VB language.[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top