VBA: How to enter a value according to another value in the same row but different column - excel

Can you please help me figure out what is the way to enter a value to a cell in one column according to a value in a different column but the same row?
let's say I don't know where is the column but I do know what is the Header name and I know how to find it and declare it as a range.
Input:
Fruit
Color
Banana
Kiwi
Watermelon
Desired Output:
Fruit
Color
Banana
Yellow
Kiwi
Green
Watermelon
Red
So far I tried:
For i = 2 To numOfDataRows
If ((RngB.Cells(i, Fruit_address).Value = "Banana") Or (RngB.Cells(i,
Fruit_address).Value = "Lemon")) Then
Rng12.Cells(i, Color_address).Value = "Yellow"
End If
Next i
RngB is my Range for the fruits column. not necessarily column B.
Rng12 is my Range for the Colors column. not necessarily column G.
Thanks in advance!

Related

Excel Formula to return all rows and columns corresponding to search string

I'm trying to lookup two sheets in Spreadsheet.
One has the search value and other has all the data corresponding to the search string.
I'm trying to find a formula that will search the value and return all the corresponding rows. Another thing is that it has to return the entire row and columns correspoing to that string and not only one.
I'm using this Vlookup formula as of now but any help will do:=
ArrayFormula(VLOOKUP(A1,Sheet2!A2:AE196,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24},FALSE))
A2:is the seach string, and used array to define the Columns to be returned.
But the formula returns only one row corresponding to the string and not all the rows.
Is there a formula that returns all rows and entire values in those rows correspoinding to the search string?
EX :Sheet1:search criteria
Search
Apple
Mango
melon
Ex:Sheet 2: Data
Name
Colour
no
Apple
red
5
Banana
yellow
3
Apple
red
25
Mango
yellow
1
Mango
yellow
10
Expected result for Apple(A1 in the formula) as search string:
Name
Colour
no
Apple
red
5
Apple
red
25
Actual result:
Name
Colour
no
Apple
red
5
You should use FILTER or QUERY
=FILTER(Sheet2!A2:AE196,Sheet2!A2:A196=A1)
=QUERY(Sheet2!A2:AE196,"select * where A='"&A1&"'",1)

append to existing values if condition is true

I want to compare the values row by row from sheet1-colors with sheet2-darkcolors
if they are both matching append the row values d and e to the fruits column in sheet 1
basically
sheet1 colors |blue |=== sheet2 darkcolors |blue| ----> fruits+yummy+yuicy
sheet1
colors
fruits
blue
bananay
red
apple
green
kiwi
sheet2
darkcolors
d
e
blue
yummy
juicy
black
tummy
fruicy
green
tummy
goosy
result
colors
fruits
blue
banana+yummy+juicy
red
apple
green
kiwi+tummy+goosy
I tried using `IF` combined with `XLOOKUP` but could not get it running together
Try-
=IFERROR(TEXTJOIN("+",TRUE,B2,INDEX(TRANSPOSE(Sheet2!$B$2:$C$4),,MATCH(A2,Sheet2!A2:A4,0))),B2)

How do I highlight a cell in Excel when all its content is contained in another column

I have a column (column A) that contains a list of text and another column (column B) that contains a smaller list, which is the values that I actually care about. Is it possible to only highlight cells in column A if all of its contents is listed in column B? If so, how?
A B
Apple Apple
Peach Pear
Apple, Pear Plum
Apple, Grape Kiwi
Apple, Pear, Kiwi      
Watermelon, Grape
So in the above example, I would like to highlight A1, A3, and A5 because all of the contents is listed somewhere in column B
use the following formula for the Conditional formatting:
=AND(ISNUMBER(MATCH(FILTERXML("<a><b>"&SUBSTITUTE($A1,",","</b><b>")&"</b></a>","//b"),$B:$B,0)))
If one does not have FILTERXML then they can use:
=SUMPRODUCT(--ISNUMBER(SEARCH("," &$B$1:$B$4&",",","&SUBSTITUTE(A1," ","")&",")))=LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1
Noting that the range $B$1:$B$4 must be the size of the lookup values without any blanks

copy value by using v lookup and LEN

I have two sheets, sheet 1 contain the data, sheet 2 will return the value from sheet 1.
sheet 1
A B
A40C7A4 BN01:Fruits for Aug-Banana
DB76FE1 BN01:Fruits for Aug-Lemon
9CCA14D BN01:Fruits for Aug-Kiwi
0274DFE BN01:Fruits for Aug-Apple
sheet 2
A B
Banana sheet1,column A value here
Lemon
Kiwi
Apple
I've tried using vlookup wildcard, but there is no value copied. Can someone please guide me on this? Thank you in advance.
You cannot use VLOOKUP to find something in a column to the right then return an associated value from a column to the left.
Try,
=INDEX(Sheet1!A:A, MATCH("*"&A2, Sheet1!B:B, 0))

Extract Value from Column A and then get the count for certain values from Column B for the value in Column A

The table structure that I have right now is as below:
Column A Column B
Apple 1
Apple 2
Apple 1
Orange 1
Orange 2
I am trying to write a formula where, for all the cells with the value of Apple in column A, I get the total count for values in column B equal to 1.
Please help.
As far as I can tell, you are just after the formula
=COUNTIFS(A:A,"Apple",B:B,1)

Resources