VBA: If cell contains [criteria] enter data

AustinRoberts32

New Member
Joined
Oct 15, 2018
Messages
3
First off, I just started to really learn vba, so I'm clueless to some of this stuff but I do know how to research and learn.
Now, I have a worksheet that I to automatically input data into cells when specific columns are changed.
I've been working and searching for hours and I have had no luck in finding anything on the internet for help. Basically when
someone enters data into any cell in column B the corresponding cell in column should have data entered depending on what was
entered in column B. If "Yes" is entered in column B, then "Already Finished" should be entered into Column I.

The following is the criteria for procedureIf Cell B2 = "Yes" Then Insert "Already Finished" in Cell I2
______________________________If "No" Then "Incomplete"
________________________________

If "ORDERED" Then "Follow Up"
________________________________

If "NSTK" Then "NSTK"
________________________________

If "OBSL" Then "OBSELETE"
________________________________Here's the code I have for it so far.

Code:
    Public Sub ChangeTest()
    Dim LastRow As Long
    Dim i As Long
      LastRow = Range("B" & Rows.Count).End(xlUp).Row
      For i = 2 To LastRow
        Select Case LCase(Range("B" & i))
          Case "no"
            Range("I" & i) = "Incomplete"
          Case "yes"
            Range("I" & i) = "Already Finished"
          Case "nstk"
            Range("I" & i) = "NSTK"
          Case "obsl"
            Range("I" & i) = "OBSLETE"
          Case "ordered"
            Range("I" & i) = "Follow Up"
        End Select
      Next i
    End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi. Right click on the appropriate sheet tab. Press view code and insert this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range, c As Range

Set rng = Intersect(Target, Columns("B"))

If Not rng Is Nothing Then
    For Each c In rng
        Select Case LCase(c.Value)
            Case "no": Range("I" & c.Row) = "Incomplete"
            Case "yes": Range("I" & c.Row) = "Already Finished"
            Case "nstk": Range("I" & c.Row) = "NSTK"
            Case "obsl": Range("I" & c.Row) = "OBSELETE"
            Case "ordered": Range("I" & c.Row) = "Follow Up"
            Case Else: Range("I" & c.Row) = ""
        End Select
    Next
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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