Vbalearner85
Board Regular
- Joined
- Jun 9, 2019
- Messages
- 139
- Office Version
- 2016
- Platform
- Windows
Hi,
I have a macro which copies data from sheet "Cdata" to "Ddata" and then loop it with per sec "timer1" macro. I do the same action with three other separate macros based on time to change copying data to 3 other sheets (Edata/Fdata/Gdata)
My question is how auto change the copy destination sheetname (from Ddata to (Edata/Fdata/Gdata) in the same macro based upon below time conditions, instead of using multiple macros
If TimeSerial(9, 0, 1) <= Time <= TimeSerial(10, 0, 0).Value Then ws = "Ddata"
If TimeSerial(10, 0, 1) <= Time <= TimeSerial(11, 0, 0).Value Then ws = "Edata"
If TimeSerial(11, 0, 1) <= Time <= TimeSerial(12, 0, 0).Value Then ws = "Fdata"
if TimeSerial(12, 0, 1) <= Time <= TimeSerial(13, 0, 0).Value Then ws = "Gdata"
I have a macro which copies data from sheet "Cdata" to "Ddata" and then loop it with per sec "timer1" macro. I do the same action with three other separate macros based on time to change copying data to 3 other sheets (Edata/Fdata/Gdata)
My question is how auto change the copy destination sheetname (from Ddata to (Edata/Fdata/Gdata) in the same macro based upon below time conditions, instead of using multiple macros
If TimeSerial(9, 0, 1) <= Time <= TimeSerial(10, 0, 0).Value Then ws = "Ddata"
If TimeSerial(10, 0, 1) <= Time <= TimeSerial(11, 0, 0).Value Then ws = "Edata"
If TimeSerial(11, 0, 1) <= Time <= TimeSerial(12, 0, 0).Value Then ws = "Fdata"
if TimeSerial(12, 0, 1) <= Time <= TimeSerial(13, 0, 0).Value Then ws = "Gdata"
VBA Code:
Sub Ddata()
Dim lastrow As Long
With ThisWorkbook
.Sheets("Cdata").Range("AA1").ClearContents
lastrow = .Sheets("Ddata").Range("A1048576").End(xlUp).Row
.Sheets("Ddata").Cells(lastrow + 1, 1).Resize(141, 25).Value = .Sheets("CData").Range("A2:Y142").Value
End With
Call Timer1
End Sub