Pull a data from excel sheet on vba macro (using excel formula)

Attrazion

New Member
Joined
Mar 11, 2023
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hi everyone!

This is the scenario, I want to pull the excel cells data using a excel formula that inside a vba macro code.
VBA Code:
Sub SendEmail()

Dim OutApp As Object, OutMail As Object
Dim TestSheet1 As String

'I can pull the data using the excel formula below, but for some reason I need it to put on vba macro code. 

TestSheet1= Worksheets(1).Range("D2").Formula = "=INDEX(B:B,MATCH(TODAY(),A:A,0))"

'I also want to add a condition that if the TestSheet1 Value = blank, then the output should be blank.

Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

With OutMail
        .To = "testTo@gmail.com"
        .Subject = "testsubject@gmail.com"
        .CC = "testemail@gmail.com"
        .Display

        'HTML Body
        .HTMLBody = TestSheet1 & .HTMLBody


    End With

    Set OutApp = Nothing
    Set OutMail = Nothing

End Sub

Output:
VBA Code:
Test Name 8

Excel, Sorry I can't download ml2bb since this company asset.
1681909085232.png
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
VBA Code:
With Application
    TestSheet1 = .WorksheetFunction.Index([B:B], .WorksheetFunction.Match(TODAY(), [A:A], 0))
End With
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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