I need to insert the current date into a specific cell using vba... Please see contents for more details.

Arrick

New Member
Joined
Feb 11, 2015
Messages
9
Good Afternoon All,

I have Excel 2013, Windows 7 Professional... I currently have the code below, and would like to change the line just above "End Sub" that contains "ActiveWorkbook.Sheets("Sheet1").range("D3") = dateString" so that it puts in the current date into that cell. I just started playing with VBA today, and am trying to get this accomplished so I can say I successfully created my first report that uses a VBA script... Can anyone help me out?


Code:
Sub RetrieveData()
'Initialize variables
Dim i As Integer
Dim URL As String
Dim sheet As String
Dim range As String
Dim dateString As String

URL = "http://***.**********.*****/RetrieveDataTable?OpenAgent&dataTable=Customers&userid=***-********&password=********&download=FALSE&includeEmptyTag=FALSE&dereference=TEXT&fieldList=emailOne_customerProfile~nameFirst_customerProfile~nameLast_customerProfile&selectionCriteria=contEnrollmentOtherEducation_customerProfile~EQ_LS~WouldYouLikeToKnowMore-yes&selectionCriteria=dateOfIntake_customerProfile~GE_LS~"
dateString = Application.InputBox("Enter a date in YYYYMMDD format")
URL = URL & dateString
'Enter the name of the sheet to insert the data into
sheet = "Sheet1"
'Enter where in that sheet you would like the data to go
range = "A1"
'Remove any previous XML maps (used for schema generation)
For i = ActiveWorkbook.XmlMaps.Count To 1 Step -1
ActiveWorkbook.XmlMaps(i).Delete
Next
'Clear the sheet so data can be inserted into it.
'NOTE: This CLEARS ALL the content in the sheet specified above
'Comment this out if you do not wish to clear all the contents on the sheet
'BUT if you are trying to insert data into cells that already have
'content in them, you will get an error message
ActiveWorkbook.Sheets(sheet).Cells.Clear
'Import XML data file, creating a new XML mapping.
ActiveWorkbook.XmlImport URL:=URL, ImportMap:=Nothing, Overwrite:=True, Destination:=ActiveWorkbook.Sheets(sheet).range(range)
'Remove the connection that was just created in the workbook
ActiveWorkbook.Connections("RetrieveDataTable").Delete
[I][B]ActiveWorkbook.Sheets("Sheet1").range("D3") = dateString[/B][/I]

End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,043
Messages
6,122,816
Members
449,095
Latest member
m_smith_solihull

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