Question : VBA - IF Condition and Fill Down, added to existing code

Experts,

Hope your afternoon is going better than mine, it is simply pouring down rain here!

The existing code in the attached spreadsheet (ThisWorkbook.SortImportedDate_To_TEMP) which was assisted by chris_bottomley, copies from worksheet DATA to TEMP the information in the correct order.

Now I need to do some conditions to further automate this operation.

1.      Within Worksheet TEMP, starting at F2 (Column named PLANTYPE), I want to lookup the value in E2 (Column named PLANNAME) and depending on what column it is in on worksheet LIST, I want to report that column name (cells B3, C3 or D3).

Example of above:
The first one (F2) would be HMO
The second one (F3) would be PPO
The third one (F4) would be HMO

Then fill this all the way down.

If a plan is not found on the list, highlight the cell in RED, so that someone knows an error has occurred (a new product exists that we need to add to the list, or there was an error during the data input).

2.      Next, on the same worksheet (TEMP), I need to fill down column G (heading GROUP), starting at G2 to the bottom of the list, with the number one. No conditions or anything needed, just a fill to the bottom.

Finally, from a design standpoint, should the information on worksheet LIST be a named range or something similar. The reason I ask this, is that I will be putting other columns that are similar within this worksheet (using LIST is my lookup for different conditions). The MAILCODE column in worksheet TEMP is similar to the HMO, PPO, TRAD option, so I want to reuse the code with different conditions. I just want to build it correctly now and not have to re-do it later if that is not the best approach. I am really new at this!

Thank you,
Kevin

***edited for content, M_matt***

Answer : VBA - IF Condition and Fill Down, added to existing code

Hi Kevin

Here is one way of doing what you want in 1 & 2.
If you add the code below it will fill column F as you requested and also add the number 1 to column G if I understand you correctly.

Whether you used a named range is up to you and what happens to the lists as time goes by.
With small lists its easy enough to refer to them as ranges.

Nick
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Sub FillF()
 
Dim Cell As Range, rng As Range
 
Range("F2").FormulaR1C1 = _
        "=IF(ISNA(VLOOKUP(RC[-1],LIST!R3C2:R50C2,1,FALSE)=RC[-1]),IF(ISNA(VLOOKUP(RC[-1],LIST!R3C3:R50C3,1,FALSE)=RC[-1]),IF(ISNA(VLOOKUP(RC[-1],LIST!R3C4:R50C4,1,FALSE)=RC[-1]),"""",LIST!R3C4),LIST!R3C3),LIST!R3C2)"
 
Set rng = [F2]
Set rng = Range(rng, Cells(Cells(Rows.Count, 1).End(xlUp).Row, rng.Column))
    If rng.Rows.Count = 1 Then
        rng.Select
    Else
        rng.Cells(1, 1).AutoFill Destination:=rng, Type:=xlFillDefault
    End If
 
For Each Cell In rng
    Cell.Offset(0, 1) = 1
    If Cell = "" Then
        Cell.Interior.ColorIndex = 3
    End If
Next Cell
 
End Sub
Random Solutions  
 
programming4us programming4us