How to use VBA to change a date in SQL query in excel

kkoruni

New Member
Joined
Jul 18, 2017
Messages
23
I need help if it is possible where I can upload SQL query in excel via Get Data>From Database>From SQL Server Database, and be able to change the date in this uploaded SQL query.
My hope is to use three cells within tab where i enter a date, and either use a vba or SQL looks cell value automatically and provide results when i refresh SQL.

Right now i have these sets of dates.
set @eomdate = '2022-10-31'
set @startdate = '2016-01-01'
set @enddate = '2022-10-31'

I want to use cells in excel that lookup date entered in cell A1, B1, and C1. My goal is to change the dates to get results based on dates entered.
set @eomdate = Sheet1A1
set @startdate = Sheet1B1
set @enddate = Sheet1C1

is there a way to use a VBA code that will change the dates based on cells mentioned above? I am researching but have been unlucky.

Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = Worksheets("Query1")
ActiveWorkbook.RefreshAll
End Sub


Any help is greatly appreciated.

Thank you,
Kosta
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:
How to use VBA to change a date in SQL query in excel

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:
How to use VBA to change a date in SQL query in excel

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Thank you for the feedback Rory.
I do not mean to **** anyone off but I thought I added the link and obviously I did a pretty bad job.

Any help with this question is greatly appreciated.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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