VBA help - Auto populate phrase based on conditions

AlwaysLearning2018

Board Regular
Joined
Nov 23, 2018
Messages
51
Hello all,

I am trying to automate a report that is run daily so I think I have to use VBA so it does not have to be touched. What I'm trying to figure out to do is for each instance in a row where I see "SA" in column J, I need the phrase "Load" to populate in every row in column O. Also if any row in column J = SWP and any row in column N = "invalid" then I need every row in column O that satisfies both criteria to = "Sweep".

Any ideas anyone can give would be greatly appreciated!!

Regards
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this formula in column O (assuming your data is in row 2):
=IF(J2="SA","Load",IF(AND(J2="SWP",N2="Invalid"),"Sweep",""))
 
Upvote 0
Here is a vba solution if that is what you need

Code:
Sub t()
Dim sh As Worksheet, c As Range
Set sh = ActiveSheet
    With sh
        .UsedRange.AutoFilter 10, "SA"
        Intersect(.UsedRange.Offset(1), .Columns("O")).SpecialCells(xlCellTypeVisible) = "Load"
        .AutoFilterMode = False
        .UsedRange.AutoFilter 10, "SWP"
        For Each c In Intersect(.UsedRange.Offset(1), .Columns("N")).SpecialCells(xlCellTypeVisible)
            If LCase(c.Value) = "invalid" Then c.Offset(, 1) = "Sweep"
        Next
        .AutoFilterMode = False
    End With
End Sub
 
Upvote 0
Thank you both! I am not having luck with the second part of the vba code. And apologies, I am looking for column O to = "Sweep" if column J = SWP AND Column N = OK. The "OK" piece is in all caps so not sure if the lcase function matters. Any help would be very much appreciated!!!
 
Upvote 0
How about
Code:
Sub AlwaysLearning2018()
   With Range("A1").CurrentRegion
      .AutoFilter 10, "SA"
      .AutoFilter 14, "OK"
      .Columns(15).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible).Value = "Load"
      .AutoFilter 10, "SWP"
      .AutoFilter 14, "Invalid"
      .Columns(15).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible).Value = "Sweep"
      .Parent.AutoFilterMode = False
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Hi Fluff,

Using this same coding, is there a way to exclude values in other columns? For example, if column K = "183" but column J does NOT equal SWP or SA I want the phrase "Not Instructed" to appear in every row of column O where these conditions are met. Thank you!!!!
 
Upvote 0
Try
Code:
Sub AlwaysLearning2018()
   With Range("A1").CurrentRegion
      .AutoFilter 10, "SA"
      .AutoFilter 14, "OK"
      .Columns(15).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible).Value = "Load"
      .AutoFilter 10, "SWP"
      .AutoFilter 14, "Invalid"
      .Columns(15).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible).Value = "Sweep"
      .AutoFilter 14
      .AutoFilter 10, "<>SWP", xlAnd, "<>SA"
      .AutoFilter 11, 183
      .Columns(15).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible).Value = "Not Instructed"
      .Parent.AutoFilterMode = False
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,604
Messages
6,173,315
Members
452,510
Latest member
RCan29

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