2

Apologies in advance as this is my first time posting something on this site and am not the best at explain issues.

I have a spread sheet, this has production data such as meters daily, meters monthly etc. These values are updated by adding TAGS from a PLC using Rockwell VantagePoint Excel add-in (if your unfamiliar with this it shouldn't matter this part is not what I am struggling with)

I need I way to copy data from one cell to another cell on the same sheet at month end. Basically the Meters monthly field needs to copied into another cell at the end of the month to record meters run for that month. The monthly meters run resets back to 0 at the end of the month.

Basically I need to copy the value in J7 into the corresponding month in W column at the end of that month. If it could ignore the year that would be advantageous as I don't need it to keep the old values and would mean I just need one column.

I have some experience at MS-Excel, also VBA but mainly in MS-Access never in MS-Excel. If answers could be explained as simply and hands on as possible it would be appreciated.

After Googling the issue I came across this formula and changed the ranges to fit my sheet but Excel doesn't like it saying it contains an error

=QUERY( A1:B6; "select B where A =date """&TEXT(TODAY();"yyyy-mm-dd")&""" "; 0 

Sorry again if I haven't explained myself properly.

Screen Grab of Spreadsheet

4
  • QUERY is a Google Sheets formula. Commented Dec 5, 2019 at 15:25
  • Hi. How do you know which month is which? Like, how would I know that J7 data is from January 2019? What are L1, L2, L3, ...? Commented Dec 5, 2019 at 15:42
  • Google Sheets - Now I feel stupid lol, Commented Dec 5, 2019 at 15:46
  • Hi Mark, L1, L2 etc are production lines, the cells (J3 - J6) are getting their data from a VantagePoint live tag and resets to 0 on the 1st of every month. So I need the value before it resets at the end of the month and paste it into the current month. Commented Dec 5, 2019 at 15:51

2 Answers 2

1

If your workbook isn't guaranteed to be open at the end of each month I would update the value every time it gets opened, like(Should be placed in ThisWorkbook):

'Runs when you open the workbook Private Sub Workbook_Open() 'Loops through U3 to the last used cell in that column For Each c In Range(Cells(3, 21), Cells(Rows.Count, 21).End(xlUp)) 'Applies the J7 value to the current month and exits the sub If Month(c) = Month(Now) Then c.Offset(, 2).Value = [J7]: Exit Sub Next c End Sub 

Also, not that it matters but, I would apply the following formula in U3:U14 to always get the correct dates:

=EOMONTH(DATE(YEAR(TODAY()),ROW()-2,15),0) 
Sign up to request clarification or add additional context in comments.

Comments

0

Okay, I'm still not super sure what the question is and I know more Access VBA than Excel VBA, but here's something that might help to find a solution.

You can make a check date function that returns a Boolean value:

Public Function EoMonthCheck() As Boolean Dim eo_month As Date, today As Date eo_month = Format(WorksheetFunction.EoMonth(Now(), 0), "yyyy-MM-dd") today = Format(Now(), "yyyy-MM-dd") If today = eo_month Then EoMonthCheck = True Else EoMonthCheck = False End If End Function 

And the,, to add a value to the "W" column, we might use something like this:

Public Function AppendValue(Optional target_cell As String = "J7") ''' This could be a subroutine, too, I guess, since we're not returning anything. Dim i As Integer ''' Activate whatever sheet you want to work with Worksheets("Sheet1").Activate If EoMonthCheck() = True Then ''' Look up the bottom of the 'W' column and find the first non-empty cell ''' Add 1 to that cell to get you to the next cell (the first empty one). i = Cells(Rows.Count, "W").End(xlUp).Row + 1 ''' Set the value of that empty cell in the 'W' column to the value of 'J7' ''' which will happen after we evaluate whether it is the end of the month. Cells(i, "W").Value = Range(target_cell).Value End If 

Then, you could maybe trigger that each time the workbook opens.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.