If Then Function in VBA

Lauren123

New Member
Joined
Mar 16, 2018
Messages
28
Hello, I have this formula but i would prefer to have it in VBA

=IF(G7="INT1",'GL Accounts'!B1&D7,"")

I would like someone to help get it on code
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,770
Office Version
  1. 2010
Platform
  1. Windows
Code:
  If Range("G7").Value2 = "INT1" Then
    Range("someCell").Value2 = Range("'GL Accounts'!B1").Value2 & Range("D7").Value2
  Else
    Range("someCell").ClearContents
  End If
... where someCell is the cell where the formula appeared.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,334
Office Version
  1. 2010
Platform
  1. Windows
Hello, I have this formula but i would prefer to have it in VBA

=IF(G7="INT1",'GL Accounts'!B1&D7,"")

I would like someone to help get it on code
You can use the formula directly (sort of... you have to double up all of the quote marks inside of the outer quote marks)...
Code:
Range("someCell") = Evaluate("=IF(G7=""INT1"",'GL Accounts'!B1&D7,"""")")
Note: Like shg's post, "someCell" should be changed to the address of the cell which the formula is currently in.
 
Last edited:

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,770
Office Version
  1. 2010
Platform
  1. Windows
Either of those alternatives will only work if the worksheet containing the G7 and D7 of interest is active when the code executes.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,500
Messages
5,529,222
Members
409,857
Latest member
KailuaTown
Top