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
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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.
 
Upvote 0
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:
Upvote 0
Either of those alternatives will only work if the worksheet containing the G7 and D7 of interest is active when the code executes.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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