+ Reply to Thread
Results 1 to 4 of 4

Making a Macro add a date after completing action

Hybrid View

  1. #1
    Registered User
    Join Date
    10-21-2008
    Location
    Perth, Australia
    Posts
    8

    Question Making a Macro add a date after completing action

    Hey Guys

    I have created a Macro that creates a new CSV from a worksheet in my workbook
    What I am trying to do is make it add a the date to B5 of my sheet called gobalsettings

    Each time I try I keep getting the error

    Run-time error '1004'
    Method 'Range' of object'_Gobal" failed

    Sub CreateCSV()
    
    Dim strFileName As String
    
    strFileName = Application.GetSaveAsFilename(filefilter:="Comma Seperated Values (*.csv), *.csv")
    
    If strFileName <> "False" Then
        Sheets("products").Copy
        ActiveWorkbook.SaveAs strFileName, xlCSV
    End If
    
    Range("GobalSettings!B4").Value = Date
    
    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Making a Macro add a date after completing action

    Hi, Bestia,

    try
    Worksheets("GobalSettings").Range("B4").Value = Date
    instead.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    10-21-2008
    Location
    Perth, Australia
    Posts
    8

    Re: Making a Macro add a date after completing action

    Thanks I tried that and got error message

    Run-time error '9':
    Subscript out of range

    Maybe I need to switch back to the original workbook

    I tried
    Workbook("Product_Prices").Worksheets("GobalSettings").Range("B4").Value = Date
    But that didnt work either

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Making a Macro add a date after completing action

    Hi, Bestia,

    once you refer to a workbooik you should have tghe extensio to that as well as part of the name.

    So if you have an xlsm workbook it may look like
    Workbook("Product_Prices.xlsm").Worksheets("GobalSettings").Range("B4").Value = Date
    But I think you may simplify if GlobalSetting is located in the same workbook Prodduct:
    Sub CreateCSV()
    
    Dim strFileName As String
    
    strFileName = Application.GetSaveAsFilename(filefilter:="Comma Seperated Values (*.csv), *.csv")
    
    If strFileName <> "False" Then
        Worksheets("GobalSettings").Range("B4").Value = Date
        Sheets("products").Copy
        ActiveWorkbook.SaveAs strFileName, xlCSV
    End If
    
    End Sub
    which would only alter the date if a string for savoing the csv is chosen.

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro Not Completing, No Errors
    By Ataraxicatom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2014, 03:56 PM
  2. Need help completing an IF function with date & time as inputs
    By Miskondukt in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-16-2014, 06:59 PM
  3. making action buttons to add and subtract cells
    By orbir1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-19-2013, 09:24 AM
  4. Help completing VBA code that emails me when expiry date 30 days before.
    By MarkBone in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2013, 03:03 AM
  5. [SOLVED] VBA Macro not completing it's task.
    By sgrondines in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-03-2012, 02:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1