Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default Macro to compare two columns and if condition is met write to a co

Hi I am new to macros. I need to write a macro that compares text in two
different columns and if the condition is met will write a numerical number
to a third column. I can do this in excel will if statements but I am
limited to only 7 nested functions. Here is the example:

IF((AND(F1="word1",G1="on")),3,IF((AND(F1="word2", G1="on")),4,IF((AND(F1="word3",G1="on")),5,0)))

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to compare two columns and if condition is met write to a co

=if(G1="on",0,MATCH(F1,{"word1","word2","word3"},0 )+2)

"Chris" wrote:

Hi I am new to macros. I need to write a macro that compares text in two
different columns and if the condition is met will write a numerical number
to a third column. I can do this in excel will if statements but I am
limited to only 7 nested functions. Here is the example:

IF((AND(F1="word1",G1="on")),3,IF((AND(F1="word2", G1="on")),4,IF((AND(F1="word3",G1="on")),5,0)))

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to compare two columns and if condition is met write to

I'm assuming the numbers will start with VIN8
number of matches is

=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"))

The toal is
=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"),C1:C100)

so the average would be
=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"),C1:C100)/B2

where b2 is the number of mattches



"joel" wrote:

=if(G1="on",0,MATCH(F1,{"word1","word2","word3"},0 )+2)

"Chris" wrote:

Hi I am new to macros. I need to write a macro that compares text in two
different columns and if the condition is met will write a numerical number
to a third column. I can do this in excel will if statements but I am
limited to only 7 nested functions. Here is the example:

IF((AND(F1="word1",G1="on")),3,IF((AND(F1="word2", G1="on")),4,IF((AND(F1="word3",G1="on")),5,0)))

Thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default Macro to compare two columns and if condition is met write to

Joel, I think I did a bad job at explaining it. I want the macro to run
through two colums and compare words in both of them and if they meet the
criteria, insert a selected number. There are 13 Different Criteria's they
have to meet but if it doesnt meet any of these conditions it enters a 0. EX
Column 1 Column 2 Column 3
dog on 1
dog off 0
cat off 0
cat on 2
hat on 3
hat off 0
sat on 4
sat off 0

Thanks
"joel" wrote:

I'm assuming the numbers will start with VIN8
number of matches is

=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"))

The toal is
=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"),C1:C100)

so the average would be
=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"),C1:C100)/B2

where b2 is the number of mattches



"joel" wrote:

=if(G1="on",0,MATCH(F1,{"word1","word2","word3"},0 )+2)

"Chris" wrote:

Hi I am new to macros. I need to write a macro that compares text in two
different columns and if the condition is met will write a numerical number
to a third column. I can do this in excel will if statements but I am
limited to only 7 nested functions. Here is the example:

IF((AND(F1="word1",G1="on")),3,IF((AND(F1="word2", G1="on")),4,IF((AND(F1="word3",G1="on")),5,0)))

Thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to compare two columns and if condition is met write to

this formula works, but I can also do it with a macro

=IF(B7="on",IF(ISNA(MATCH(A7,{"dog","cat","hat","s at"},0)),0,MATCH(A7,{"dog","cat","hat","sat"},0)), 0)

Sub CompareData()

Data = Array("dog", "cat", "hat", "sat")

RowCount = 1
Do While Range("A" & RowCount) < ""
If UCase(Range("B" & RowCount)) = "OFF" Then
Range("C" & RowCount) = 0
Else
CellData = Range("A" & RowCount)

found = False
For ItemCount = 0 To UBound(Data)
If Data(ItemCount) = CellData Then
Range("C" & RowCount) = ItemCount + 1
found = True
Exit For
End If
Next ItemCount
If found = False Then
Range("C" & RowCount) = 0
End If
End If
RowCount = RowCount + 1
Loop


End Sub





"Chris" wrote:

Joel, I think I did a bad job at explaining it. I want the macro to run
through two colums and compare words in both of them and if they meet the
criteria, insert a selected number. There are 13 Different Criteria's they
have to meet but if it doesnt meet any of these conditions it enters a 0. EX
Column 1 Column 2 Column 3
dog on 1
dog off 0
cat off 0
cat on 2
hat on 3
hat off 0
sat on 4
sat off 0

Thanks
"joel" wrote:

I'm assuming the numbers will start with VIN8
number of matches is

=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"))

The toal is
=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"),C1:C100)

so the average would be
=SUMPRODUCT(--(LEFT(A1:A100,14)="VIN81FTDF15YS),--(B1:B100="myarea"),C1:C100)/B2

where b2 is the number of mattches



"joel" wrote:

=if(G1="on",0,MATCH(F1,{"word1","word2","word3"},0 )+2)

"Chris" wrote:

Hi I am new to macros. I need to write a macro that compares text in two
different columns and if the condition is met will write a numerical number
to a third column. I can do this in excel will if statements but I am
limited to only 7 nested functions. Here is the example:

IF((AND(F1="word1",G1="on")),3,IF((AND(F1="word2", G1="on")),4,IF((AND(F1="word3",G1="on")),5,0)))

Thanks


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 adjacent columns for a specified condition [email protected] Excel Programming 1 October 25th 07 12:19 AM
macro to compare file columns Mike Excel Programming 0 December 15th 05 09:21 PM
Macro to compare two columns of data Odawg Excel Discussion (Misc queries) 1 October 12th 05 02:51 PM
Macro to compare two columns of data Odawg Excel Discussion (Misc queries) 0 October 12th 05 03:13 AM
How do I write a VBA code in excel that will compare two columns . PenelopeinCinci Excel Worksheet Functions 2 April 14th 05 05:27 PM


All times are GMT +1. The time now is 07:08 PM.

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"