IF and Left

valemarje

New Member
Joined
Apr 20, 2022
Messages
31
Office Version
  1. 2016
Platform
  1. Windows
I currently use the formula

Range("D2").Select
ActiveCell.FormulaR1C1 = _
"=IF(LEFT(RC[-2],5)=""DAVID"",""DAVIDE"","""")))))"

but I would like to be able to put something like this, only I don't know the correct way:

If Range(B2).value (LEFT(RC[-2],5) = "DAVID"
Range("D2").value ="DAVIDE"
else
Range("D2").value =""
end if

Can you help me?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Welcome to the Board!

Is this what you are looking for?
VBA Code:
If Range("B2").Value = "DAVID"
    Range("D2").Value ="DAVIDE"
Else
    Range("D2").Value =""
End if

If so, why even bother adding nothing to cell D2, instead of just doing nothing to it, i.e.
VBA Code:
If Range("B2").Value = "DAVID"
    Range("D2").Value ="DAVIDE"
End if
 
Upvote 0
You are welcome.

Is that what you were looking for?
 
Upvote 0
but i need whit if...

IF(LEFT(RC[-2],5) not only
If Range("B2").Value = "DAVID"
 
Upvote 0
IF(LEFT(RC[-2],5) not only
If Range("B2").Value = "DAVID"
That does not make any sense. You cannot move two columns to the left of column B. That would take you off of the page.

Can you just explain in plain English what you are trying to do?
 
Upvote 0
In column B there are alphanumeric codes... depending on how they start in the corresponding line in column D I have to put a word that will be my category

So I made the example if the code in B2 starts with DAVID (example) in D2 I will put DAVIDE
If the code in B3 starts with MIS I will put "MIXER" in D3
If the code in B4 starts with MISS I will put "MISSION" in D4
etc...
 
Upvote 0
In column B there are alphanumeric codes... depending on how they start in the corresponding line in column D I have to put a word that will be my category

So I made the example if the code in B2 starts with DAVID (example) in D2 I will put DAVIDE
If the code in B3 starts with MIS I will put "MIXER" in D3
If the code in B4 starts with MISS I will put "MISSION" in D4
etc...
Then it should just be something like this:
VBA Code:
If Left(Range("B2").Value, 5) = "DAVID"
    Range("D2").Value ="DAVIDE"
End if
if you want to hard-code the value into column D instead of inserting a formula.
 
Upvote 0
sul cellulare semplice penso che funzioni ed è esattamente quello che volevo quindi ti ringrazio.

come faccio a dirgli di ripetere per ogni riga da B2 a B6000, ad esempio?
e mettere i dati corrispondenti da D2 a D6000?
 
Upvote 0
on the simple cell I think it works and that is exactly what I wanted so I thank you.

how do i tell it to repeat for each row from B2 to B6000 row for example?
and put the corresponding data from D2 to D6000?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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