Forum Discussion

Shalee0128's avatar
Shalee0128
Copper Contributor
Oct 09, 2023
Solved

Push data to the right and empty cell automatically

Hey all I'm trying to make a tracking spreadsheet for the last date something was cleaned. So column one would be the name of the item, and in my mind column two would be where you would place the da...
  • NikolinoDE's avatar
    Oct 09, 2023

    Shalee0128 

    It is possible to create a tracking spreadsheet in Excel where the data shifts to the right and clears out column two automatically when a date is enter. You can achieve this using a formula and a simple data entry process. Here is a step-by-step guide:


    1. Set Up Your Spreadsheet
      :
      • Column A: Item Names
      • Column B: Last Cleaned Date (initially empty)
      • Column C onwards: Historical Cleaned Dates
    2. Enter the Date Entry Formula:

    In cell B2 (assuming your data starts in row 2), enter the following formula:

    =IF(B2<>"", B2, "")

    This formula checks if cell B2 is not empty. If it is not empty, it displays the date; otherwise, it displays an empty cell.

    1. Data Entry Process:
      • Enter the name of the item in column A.
      • In column B (Last Cleaned Date), enter the date when the item was last cleaned.
      • Press Enter.

    The date will appear in column B, and column B will be cleared for the next entry.

    1. Historical Data:
      • To record historical data, simply drag the formula from cell C2 to the right (C2, D2, E2, etc.) to create additional columns for historical dates.

    For example, in cell C2, you can use this formula:

    =IF(COUNT($B2:B2)>COLUMN(C2)-COLUMN($C$2), INDEX($B2:B2, COLUMN(C2)-COLUMN($C$2)+1), "")

    This formula retrieves the last entered date in column B and shifts it to the right into column C when a new date is entered in column B.

    1. Repeat the Data Entry Process:
      • Continue entering item names and dates in column B as needed.

     

    This method does not use macros and relies on Excel formulas to display and shift the date entries. It is a manual process, but it achieves the desired result without the need for programming.

    If you want a automatically process you need VBA.

    Here is a step-by-step guide to set it up:

    1. Open Excel: Open your Excel spreadsheet.
    2. Press ALT + F11: This will open the Visual Basic for Applications (VBA) editor.
    3. Insert a Module: In the VBA editor, go to Insert > Module. This will insert a new module where you can write your VBA code.
    4. Enter the following VBA code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Column = 2 And Target.Value <> "" Then
            Dim LastCol As Long
            LastCol = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
            Cells(Target.Row, LastCol + 1).Value = Target.Value
            Target.ClearContents
        End If
    End Sub

    This code will trigger whenever there is a change in column 2 (B) and if the cell is not empty. It will then find the last used column in the row and move the entered date to the next empty column to the right and clear the original cell.

    1. Close the VBA Editor: After pasting the code, close the VBA editor.
    2. Test Your Spreadsheet: Now, when you enter a date in column B (e.g., B2), it will automatically move to the next available column to the right, and the original cell will be cleared for the next entry.

    Make sure to save your workbook as a macro-enabled workbook (with the .xlsm extension) if it is not already saved in that format.

     

    Please note that using VBA macros may require enabling macros in your Excel settings, and you should be cautious when working with macros as they can affect your Excel workbook's behavior.

    All specified formulas and VBA code may vary in functionality depending on the Excel version, operating system, storage medium. All specified formulas and VBA code have not been tested, please save the file in advance.The text, steps, VBA Code and functions were created with the help of AI.

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

    Was the answer useful? Mark as best response and Like it!

    This will help all forum participants.

     

Resources