Consulting

Results 1 to 4 of 4

Thread: I want to copy a value from a previous sheet, every day.

  1. #1
    VBAX Newbie
    Joined
    Feb 2022
    Posts
    1
    Location

    I want to copy a value from a previous sheet, every day.

    Hi everybody,

    See file : I have an automatic copy of the sheet "Padrão" with an automatic filename = the date of the day.
    All coded. This commandbutton is not show on the file.
    To past the value of I35 to the next day in the cellI I34, i do it manually.

    I will this coded.

    My code to try this :

    Private Sub CommandButton1_Click()
    ‘Creation of the formula in a cell Range(“I34’”)  of today’s sheet
                    Dim Fname As Variant
                    Fname = Format(Date - 1, "DD-MM-YYYY")
    ‘ Select  yesterdays sheet (sheetname is Fname), select a cell  value
                    Range("I35").Select
    ‘ Sheet of today
    ‘Past formula in the sheet of today in cell “I34”    
                    ActiveCell.FormulaR1C1 = "='fname'!R[1]C" (This doesn’t work!!!!!)
    End Sub
    This should be done every day automatically.

    I need some help.
    Attached Files Attached Files
    Last edited by Aussiebear; 02-05-2022 at 01:49 PM. Reason: Added code tags to supplied code

  2. #2
    VBAX Contributor rollis13's Avatar
    Joined
    Jun 2013
    Location
    Cordenons
    Posts
    146
    Location
    Not sure I understood your request because I don't realize what your are trying to do in the above example.
    Anyway, in your file you have a working macro, why don't you cut/paste it into the ThisWorkbook (EstaPastaDeTrabalho) module and call it Private Sub Workbook_Open() instead of "Private Sub CommandButton1_Click()". It will be launched every time you open the file.
    Now all you have to do is add to it a test to avoid it duplicating the day's sheet in case you need to reopen the file the same day.
    Option Explicit
    Private Sub Workbook_Open()
        Dim sztoday, dztoday
        'Copy the master
        Worksheets("Padrão").Copy After:=Worksheets(Worksheets.Count)
        'Change ActiveSheet name
        sztoday = Format(Date, "DD-MM-YYYY")
        ActiveSheet.Name = sztoday
        'Copy A range of Data
        Sheets(Sheets.Count - 1).Select
        ActiveSheet.Range("I35").Copy
        Sheets(Sheets.Count).Select
        ActiveSheet.Range("I34").PasteSpecial Paste:=xlPasteValues
        ActiveSheet.Range("I34").FormatConditions.Delete
        dztoday = Format(Date, "dddd, dd mmmm yyyy")
        ActiveSheet.Range("A5").Value = dztoday
    End Sub

  3. #3
    on the Ribbon->Home, there is a Button on the Rightmost.
    it will create new sheet based on Padrão sheet and will be named
    as Today's date.
    Attached Files Attached Files

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Dim ShYName As String, ShTName As String
    
    ShYName = Format(Date - 1, "dd-mm-yyyy")
    ShtName = Format(Date,"dd-mm-yyyy")
    
    Sheets(ShTName).Range("I34") = Sheets(ShYName).Range("I35")
    End Sub
    Or
    Dim YValue
    YValue = Sheets(Format(Date - 1, "dd-mm-yyyy")).Range("I35").Value
    Sheets(Format(Date,"dd-mm-yyyy")).Range("I34") = YValue
    End Sub
    Lastly
    Sheets(Format(Date,"dd-mm-yyyy")).Range("I34") = Sheets(Format(Date - 1, "dd-mm-yyyy")).Range("I35")
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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