Sub Macro1()
'
' Macro1 Macro
'
'
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=1,""yes"",""no"")"
Range("B2").Select
End Sub
I am trying to get my head wrapped around basic concept but nothing I found helps.
In A1 i have the value 1
in B1 =if(a1=1,"yes","no)
When I press enter yes appears, duh. Can somebody show me what this would look like in VBA form?
If Range("A1").Value = 1 then
Range("B1").Value = "yes"
Else
Range("B1").Value = "no"
end if
Yes I know. But it looks like this only looks at b2. I dont want that. I want to know how to enter =myFunction(anyCell) and it processesCode:Sub Macro1() ' ' Macro1 Macro ' ' ActiveCell.FormulaR1C1 = "=IF(RC[-1]=1,""yes"",""no"")" Range("B2").Select End Sub
You know that you can record macros correct? I've learned countless functions like this just by doing simple 1 step recordings.
if(anyCell=1){
currentCell.Value ="yes"
}else{ currentCell.Value="no"}
Thanks Scott. How would I make Range("A1") a variable and Range("B1") the current cell?
So you want it to say instead of Range("A1").Value = 1, you want to know how to select a broader range like all of column A?Scott, This was just me trying to learn. I just wanted to understand how if i can click in any cell (say b99) and see if any other cell (that I specify) equals 1. If it does put "yes" in that cell (b99) for this sample if not put "no".
If Range("A:A").Value = 1 then
Range("B:B").Value = "yes"
Else
Range("B:B").Value = "no"
end if
So you want it to say instead of Range("A1").Value = 1, you want to know how to select a broader range like all of column A?
This would apply to all cells in column B (based on presence of "1" in corresponding A cell)Code:If Range("A:A").Value = 1 then Range("B:B").Value = "yes" Else Range("B:B").Value = "no" end if
is this what you are wanting to know?
sub macro1()
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",IF(RC[-1]=1,""yes"",""no""))"
Range("B1").Select
Selection.Copy
Columns("B:B").Select
ActiveSheet.Paste
Application.CutCopyMode = False
end sub