Microsoft office home and student 2016 (Windows 10 Home 64bit)
Posts
98
Every 1 hour data should copy paste from A to B, then A to C and so on
hello,
I have a Product list in Column which every hour "A" with conditionally formatting red and green (red = sold, green = purchase) which every hour needs to record manually in column B then C then D, and so on
need your help with VBA code or formula so can do this automatically
Product list
A B C D E
1 Fan
2 Switch
3 Wire
4 tapes
5 pins
6 sockets
7 board
8
9
10
11
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Could you post a image/screenshot of sample worksheet?
I dont know how to define the last column to paste column A into after each hour. Are there any data in other column to the right. i.e, AA or AB,...?
Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
MS-Off Ver
MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
Posts
80,779
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Please attach the workbook, NOT a picture of it!
Ali Enthusiastic self-taught user of MS Excel who's always learning! Don't forget to say "thank you" in your thread to anyone who has offered you help.
You can reward them by clicking on * Add Reputation below their user name on the left, if you wish. Forum Rules (updated August 2023): please read them here.
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Maybe below code pasted into module
PHP Code:
Option Explicit Public t As Long ' set timer Sub timer() t = Hour(TimeValue(Now)) + 1 ' set next run time to next hour from now, stop at 17h Application.OnTime Date + t / 24, "copyRng", Date + 17 / 24 End Sub Sub copyRng() Dim lr&, copyRng As Range, pasteRng As Range lr = Cells(Rows.Count, "A").End(xlUp).Row t = Hour(TimeValue(Now)) 'current hour Set copyRng = Range("A6:A" & lr) On Error Resume Next Set pasteRng = Range("A6").Offset(0, t - 6) Range("A6:A" & lr).copy pasteRng pasteRng.EntireColumn.AutoFit On Error GoTo 0 End Sub
Microsoft office home and student 2016 (Windows 10 Home 64bit)
Posts
98
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Instead of 1 hour will it be possible to make 15 minutes or 30 minutes
Like
Starting Time 8:00 AM than next column 8.15 - 8.30 - 8.45 - 9.00 - 9.15 - 10 - 10.30 - 10.45 - 11 so on till 17:00
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Try again:
PHP Code:
Option Explicit Public t As Double ' set timer Sub timer() t = WorksheetFunction.Ceiling(Minute(TimeValue(Now)), 15) 'current minute (in whole number)round upto next 15 ' set next run time to next hour from now, stop at 17h Application.OnTime Date + Hour(TimeValue(Now)) / 24 + t / 1440, "copyRng", Date + 17 / 24 End Sub
'------------------ Sub copyRng() Dim lr&, copyRng As Range, pasteRng As Range lr = Cells(Rows.Count, "A").End(xlUp).Row With WorksheetFunction t = .Ceiling(TimeValue(Now), 15 / 1440) 'current minute round upto next 15' Set copyRng = Range("A6:A" & lr) On Error Resume Next Set pasteRng = Range("A6").Offset(0, .Match(t, Range("C5:AM5"))) Range("A6:A" & lr).Copy pasteRng pasteRng.EntireColumn.AutoFit On Error GoTo 0 End With End Sub
Microsoft office home and student 2016 (Windows 10 Home 64bit)
Posts
98
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Thank you very much.
15 minutes is perfect but doesn't know, the automatic thing is not working.
Every time have to go to code and press run to paste the next column.
Microsoft office home and student 2016 (Windows 10 Home 64bit)
Posts
98
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Hello guys,
Mr. Bebo 021999 did a perfect timer part but unfortunately auto update not working.
If anyone or Mr Bebo 021999 please help me out it will be great.
Microsoft office home and student 2016 (Windows 10 Home 64bit)
Posts
98
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Hi,
Thanks again Bsalv and Bebo.
Previously, the VBA code had to be pressed every 15 minutes to run. But now when I open the file the timer doesn't start. The timer starts only when I have to run the VBA code.
Please check the uploaded file if the formula is added in the A column then the pasting source is changed automatically.
Microsoft office home and student 2016 (Windows 10 Home 64bit)
Posts
98
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
Hello Bebo and bsalv,
Please allow me to extend my question.
Your code is perfect only I need 2 things to add, please.
1) This timer keeps showing a full day which is not desired. Would it be possible to show the timer only for the time we set the timer for? and stop showing when the set timer expires. (Timing only between 8 am to 5 pm)
2) The result data should be cleared on the next day before the new day timer starts.
Re: Every 1 hour data should copy paste from A to B, then A to C and so on
hello.
see attachment
your point 1 = this correction
If Hour(t) < 8 Then t = Date + TimeSerial(8, 0, 1) 'before 8 AM
If Format(t, "hh:mm") > "17:00" Then t = Date + 1 + TimeSerial(8, 0, 1) 'after 5PM
your point 2 = this correction
With c(2, col + 1).Resize(20, 40) 'everything to the right of the actual column is empty with this
.ClearContents
.Interior.Color = xlNone
.EntireColumn.ColumnWidth = 5
End With
Bookmarks