Modify cells in every row

Ignition1

New Member
Joined
Feb 22, 2011
Messages
49
Hi
I have a lonnnnng list.

I want to create a module within VBE (as I will "Call" it during a longer macro) which will look at each row and do -

A1 = Start Date
G1 = Today's date
Q1 = Income
J1 = Duration (single figure - months).
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Something like this?

Code:
Public Sub RearrangeData()
Dim i   As Long, _
    LR  As Long
    
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Range("Q" & i).Value = Range("A" & i).Value
    Range("A" & i).Value = Range("G" & i).Value
Next i
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
End Sub
 
Upvote 0
If A1 < G1 Then ( Q1 / J1) * ( DATED IF(A1,G1,"m")

Return that new figure into Q1 AND replace A1 with the date in G1.

So basically modifying the value in Q1 and replacing A1. But doing the check for every row (about a thousand rows) and only modifying the rows where A1<G1.

Sorry for posting in 2 messages - for some reason the post wouldn't display properly
 
Last edited:
Upvote 0
Once again - sorry, I can't post formulas as it doesn't like that. So I've typed out in plain ol' English what I'm trying to do -

If the Start Date (A) is less than Date (G) then in that row, divide Income (Q) by Duration (J) and multiply that amount by the difference in months between the dates in A and G. Then replace the value in Q with this new modified figure, and also replace the date in A with the date in G for that row only.

Skip any row where A is NOT less than G.
 
Upvote 0
That's a much better explanation. Try:

Code:
Public Sub RearrangeData()
Dim i   As Long, _
    LR  As Long
    
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Range("A" & i) < Range("G" & i) Then
        Range("Q" & i).Value = (Range("Q" & i).Value / Range("J" & i).Value) * Evaluate("DATEDIF(" & Range("A" & i).Value & "," & Range("G" & i).Value & ", ""m"")")
Next i
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
End Sub
 
Upvote 0
That looks like the one - thanks very much!

I did have a problem on Excel (using the function) with the DATEDIF returning a value which wasn't recognised a number. I'll give this a bash.

I also suppose if I want to replace the date in A then it would be -

Code:
If Range("A" & i) < Range("G" & i) Then
        Range("Q" & i).Value = (Range("Q" & i).Value / Range("J" & i).Value) * Evaluate("DATEDIF(" & Range("A" & i).Value & "," & Range("G" & i).Value & ", ""m"")")
        Range("A" & i).Value = (Range("G1").Value
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
rootytrip

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