PDA

View Full Version : I want to copy a value from a previous sheet, every day.



AnBu
02-05-2022, 09:09 AM
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.

rollis13
02-05-2022, 04:57 PM
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

arnelgp
02-05-2022, 09:13 PM
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.

SamT
02-07-2022, 06:02 PM
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