Question:

How can VBA (excel) match cell values and paste if true?

by  |  earlier

0 LIKES UnLike

I am trying to figure out how to build a loop, or if/then, to get the following to work:

In Sheet "08" I am using 2 columns: C (Date), K (empty)

In Sheet "Conv" I am using 2 columns: A (Date), F (calculated %)

I need to compare the dates in column 08.B to column Conv.A to see if they are equal. However, they are not 1:1, but column 08.B repeats the same date multiple times while column Conv.A only has it once. If they don't equal, I need to go through until they match up again (Eg; column 08.B might have 3/3/2008 twelve times and needs to match to the 3/3/2008 column Conv.A each time). If it does match, then I copy the value in Conv.F and paste it into 08.K (the same value for the date will repeat until a new date in column 08.B is reached). I need this to repeat until column 08.B is empty (there are no more dates to compare/retrieve data for).

Here's a basic example/layout of the spreadsheet:

Sheet "08"

-Column B (date)---------Column K(empty - where paste happens)

-3/3/2008--------------------

-3/3/2008--------------------

-3/3/2008--------------------

-3/4/2008--------------------

-3/4/2008--------------------

-3/5/2008--------------------

-3/5/2008--------------------

-3/5/2008--------------------

-3/6/2008--------------------

...and so on

Sheet "Conv"

--Column C(date)-----Column F(number %)

-3/3/2008---------------- .45

-3/4/2008---------------- .67

-3/5/2008---------------- .89

-3/6/2008---------------- .86

-3/7/2008---------------- .54

Thanks, any help is greatly appreciated!

 Tags:

   Report

1 ANSWERS


  1. You can do it without VBA, although I find VBA more fun.

    Assuming you are starting in K1, copy this formula to K1 and fill down.  The $C$1 reference is the first Date cell in sheet Conv.  The $F$5 reference is the last 'number %' value .  Change these references to meet your needs.  Make sure to keep the '$'

    =If(B1="","",VLOOKUP(B1,

    Conv!$C$1:$F$5,4,FALSE))

    Note: This should all be one complete formula. Yahoo Answers just isn't up to the task of keeping it all in one line for display purposes.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions