Hi there
Could you please help me with my code, I don't know where I went wrong or whether I have missed out anything. I have attached the data as well as my module that I have done so far.
Thank you
Hi there
Could you please help me with my code, I don't know where I went wrong or whether I have missed out anything. I have attached the data as well as my module that I have done so far.
Thank you
Last edited by ixthus; 09-20-2013 at 05:43 AM.
maybe "Cells" instead of "Cell"
I just have one more problem.
My module doesn't run as the name "Sub MovingAverage" can't be defined as noted on the compile error that pops up.
Pl see the attached edited macro.
![]()
Option Explicit Sub MovingAverage() Dim i, j, row_n, col_m As Integer Dim total As Double Dim wks As Worksheet Dim last As Integer Dim total_num As Double 'Last 5 days last = 5 Set wks = Worksheets("FOREIGN EXCHANGE RATE") row_n = wks.Range("A2").CurrentRegion.Rows.Count col_m = wks.Range("A2").CurrentRegion.Columns.Count For i = 5 To row_n - 1 Cells(i + 5 - 1, 2) = Range(Cells(i, 1), Cells(i + 5 - 1, 1)) Next i For i = 10 To row_n - 1 Cells(i + 5 - 1, 3) = Range(Cells(i, 2), Cells(i + 5 - 1, 2)) Next i For i = 5 To row_n - 3 ' value changed If Cells(i, 1) <> Cells(i, 2) Then 'calculate moving average for the last 5 days' wks.Cells(i, 1) = Application.WorksheetFunction.Average(Range(wks.Cells(i + 5 - 1, 1), wks.Cells(i + 5 - 2, 2))) End If Next i End Sub
I'm having difficulties with the VBA programming, just wondering if someone could give a basic example of how to set up a mortgage loan calculator using VBA?
Cheers.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks