How to create a VBA to move one data point to another column to create historical data table.

beccadavis3

New Member
Joined
Dec 16, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have one data point in excel (K28) that I want to autmoatically move everytime the spreadsheet is opened to another column (N7) to start a table creating a historical trend. Therefore the data point that the information is being moved to will need to automatically populate on the next row. Is there a way to create a Macor or VBA to do this?
 

Attachments

  • Screenshot 2024-12-16 132523.png
    Screenshot 2024-12-16 132523.png
    33 KB · Views: 3

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
like this ?

*Paste VBA Code in 'ThisWorkbook' object, see below image

VBA Code:
Private Sub Workbook_Open()
    Dim ws As Worksheet, ls As Long
    
    Set ws = ThisWorkbook.Sheets(1)  'Change with ur sheet name
    ls = ws.Cells(Rows.Count, "N").End(xlUp).Row + 1
    
    With ws
        .Range("N" & ls).Value = .Range("K28").Value
        .Range("K28").ClearContents 'if u want to delete K28 after workbook opened
    End With
    MsgBox "Data Moved !"
End Sub


1734403890301.png
 
Upvote 1
Try this worksheet event.
VBA Code:
Private Sub Worksheet_Activate()
Dim ro&
If Range("K28") <> "" Then
If Range("N7") = "" Then ro = 7 Else ro = Range("N" & Rows.Count).End(xlUp).Row + 1
Range("K28").Cut Range("N" & ro)
End If
End Sub
How to use worksheet event the code
Right click on Sheet tab --> view code
Visual Basic (VB) window opens.
Select worksheet in drop down instead of General
Paste the code
Close the VB window.
Save the file as .xlsm
 
Upvote 0

Forum statistics

Threads
1,224,803
Messages
6,181,055
Members
453,015
Latest member
ZochSteveo

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