Shift cell fill color daily

draker

New Member
Joined
Sep 20, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I'm very new to VBA and am struggling to find a solution to this. I have a column of equipment and rows of dates to act as a checkout system. The idea is a person would add their name to the dates and the date along with the name shifts 1 cell left daily so that column B is always the current day. Currently, the code I have works perfectly to achieve this but I am wanting to add the functionality of including any cell fill color to also shift 1 cell left every day. Would someone have any suggestions what I could add or modify to this existing code to include fill color? If you need any additional information or clarification let me know

VBA Code:
Private Sub Worksheet_Calculate()
' check if first day is changed
If [b8] = [z1] Then Exit Sub

  Dim a, i As Long
  
On Error GoTo CleanExit:
Application.ScreenUpdating = False
Application.EnableEvents = False

' days since last data shift
i = [b8] - [z1]

If i > 0 And i < 7 Then
    'store data to shift
    a = Range(Cells(10, 1 + (i + 1)), Cells(40, 63)).Value
    
    'clear old data
    Range("b10:bk40").ClearContents
    
    'write stored data
    Cells(10, 2).Resize(31, 62 - (i)) = a

Else
    'clear old data
    Range("b10:bk40").ClearContents

End If

    
' store new date
Range("z1") = Range("b8").Value


Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub

CleanExit:
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Err.Clear
  
End Sub
Screenshot 2023-09-20 121236.png
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
My first thought would be to delete the portion of column B, maybe B7:B20, and shift the remaining data left. Of course, copy the data elsewhere first if it needs to be saved.

VBA Code:
Range("B7:B20").Delete Shift:xlToLeft
 
Upvote 0
Solution
My first thought would be to delete the portion of column B, maybe B7:B20, and shift the remaining data left. Of course, copy the data elsewhere first if it needs to be saved.

VBA Code:
Range("B7:B20").Delete Shift:xlToLeft
I had to change the syntax a bit, Shift:=xlToLeft, but that works great! Much simpler too. Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,031
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top