Fill Cell based on Specific Row and Column Text

temerson

New Member
Joined
Apr 22, 2019
Messages
39
Hello,

I have a matrix and want to create a code if it finds a specific text in a column (Column F) and row (Row 3), it will fill a cell starting on Column V with "-". The issue I have is having the row dynamic where it if it finds "eggs" and "AZ" in column, it will fill the cell with "-".

I have the following piece of a code below but cannot combine it together where it works.

'searches for AZ
Set wsText = ActiveWorkbook.Worksheets("Text")
nLastCol = wsText.Cells.Find("*", LookIn:=xlValues, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column

For i = nLastCol To 22 Step -1
If InStr(1, wsText.Cells(3, i).Value, "AZ", vbTextCompare) > 0 Then
Else
'this is where I get stuck, I am assuming this is where I put the 'searches for eggs in a specific column code
End If

'searches for eggs
Set wsText = ActiveWorkbook.Worksheets("Text")
nLastRow = wsText.Cells.Find("*", LookIn:=xlValues, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
For i = nLastRow To 13 Step -1
If InStr(1, wsText.Cells(i, 6).Value, "EGGS", vbTextCompare) > 0 Then
Else

End If


Thanks in advance!
 

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
Ok, thanks for that. How about
VBA Code:
Sub temerson()
   Dim Cl As Range, Rng As Range
   
   With Range("V3:OM3")
      .Replace "AZ", True, xlWhole, , False, , False, False
      Set Rng = .SpecialCells(xlConstants, xlLogical)
      .Replace True, "AZ", xlWhole, , False, , False, False
   End With
   For Each Cl In Range("F13", Range("F" & Rows.Count).End(xlUp))
      If InStr(1, Cl.Value, "eggs", vbTextCompare) > 0 Then
         Intersect(Cl.EntireRow, Rng.EntireColumn).Value = "-"
      End If
   Next Cl
End Sub
 
Upvote 0
Does that code work, if the relevant sheet is active?
 
Upvote 0
It works if I put it in a separate sub - my goal is to have this code execute in a specific worksheet if a user types in an answer into an input box
 
Upvote 0
That's fine I just wanted to check it does what you need before changing anything.
What is the name of the sheet it should run on?
 
Upvote 0
Ok, try
VBA Code:
Sub temerson()
   Dim Cl As Range, Rng As Range
   
   With Sheets("Chino")
      With .Range("V3:OM3")
         .Replace "AZ", True, xlWhole, , False, , False, False
         Set Rng = .SpecialCells(xlConstants, xlLogical)
         .Replace True, "AZ", xlWhole, , False, , False, False
      End With
      For Each Cl In .Range("F13", .Range("F" & Rows.Count).End(xlUp))
         If InStr(1, Cl.Value, "eggs", vbTextCompare) > 0 Then
            Intersect(Cl.EntireRow, Rng.EntireColumn).Value = "-"
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,447
Members
449,453
Latest member
jayeshw

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