Shifting Cells Right when data present within a table.

IHaveQuestion

New Member
Joined
Sep 12, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am trying to create a system for recording observations and visits to locations. I would like to be able to input information into the first three New Visit columns, and it will shift all 3 corresponding columns over to the older visits. Every time I add a data set( or fill out the three columns, I want the older visits to shift over again to leave space to fill out the next visit when it happens. This would leave the most recent visit farthest to the left in the older visits columns. This needs to be row independent, as I will have multiple different Places to visit, and don't want to move all of the data over every time I add a "visit" The only way I have been able to figure this out so far is to copy the cells over every time. I am doing this in a table within a workbook as well (to allow for easy sorting of the locations,) so excel is not letting me "shift cells right". This shift cells right is the exact functionality I am looking for, but am trying to automate it, maintain the desired formatting, and do it within a table.

Is there a way to do this? I think the easiest way would be to shift the three cells right if data was entered (if this can be done in a table). I am also open to other ideas to achieve the same result: A record of these visits and reasonings keeping the most recent information easily visible with other location specific information (not shown in sample image)

I have attached a image to try and show what I am trying to do.

1694541846975.png
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
If this were my project, and it isn't, I'd make the table as wide as you think it will ever need to be and then use this code in the sheet module.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    'limit to single cell at a time
    If Target.CountLarge <> 1 Then Exit Sub
  
'only concerned with columns 2,3,4 of table
    Dim oLo As ListObject
    Dim hdR As Long, lsR As Long
    Dim rng As Range
  
    Set oLo = Sheets("Sheet1").ListObjects("Table1")
    Set rng = oLo.ListColumns(2).DataBodyRange.Resize(, 3)
  
    If Not Intersect(Target, rng) Is Nothing Then
        hdR = oLo.HeaderRowRange.Row
        lsR = Target.Row - hdR
        With oLo.DataBodyRange(lsR, 2)
            If Application.WorksheetFunction.CountA(.Resize(, 3)) = 3 Then
                Application.EnableEvents = False
                .Offset(, 3).Resize(, oLo.ListColumns.Count - 4).Value = .Resize(, oLo.ListColumns.Count - 4).Value
                .Resize(, 3).ClearContents
                .Select
                Application.EnableEvents = True
            End If
        End With
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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