Help VBA Adding 4 Previous columns When Column Matches Criteria

LNG2013

Active Member
Joined
May 23, 2011
Messages
465
Hello -
I need help with some VBA targeting any of the columns that contain "AIFinal" in their header. Then adding the 4 previous rows into this column.
There are approximately 20 "AIFinal" columns in the sheet, and approximately 60,000 rows of data
Example of the end result I am looking for below.

AI701
AI501
AI401
AI301
AIFinal01
6
6
2
2
4
4
5
5

<tbody>
</tbody>

Rudimentary code capture below.

Sub AIFillUp()
'
' AIFillUp Macro

Range("AT2").Select
ActiveCell.FormulaR1C1 = "=RC[-4]+RC[-3]+RC[-2]+RC[-1]"
Range("AT2").Select
Selection.AutoFill Destination:=Range("AT2:AT385"), Type:=xlFillDefault

End Sub

Thank you fgor any and all help
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Do the AI701 etc cells have formulae, or are they hard values?
 
Upvote 0
It would help if you answered the question I asked 4 days ago. ;)
 
Upvote 0
Ok, how about
Code:
Sub LNG2013()
   Dim Cl As Range
   Dim UsdRws As Long
   
   UsdRws = Cells.Find("*", , , , xlByRows, xlPrevious, , , False).Row
   With Range("1:1")
      .Replace "Aifinal", "=xxxAIFinal", xlPart, , False, , False, False
      For Each Cl In .SpecialCells(xlFormulas, xlErrors)
         Cl.Offset(1).Resize(UsdRws - 1).FormulaR1C1 = "=RC[-4]+RC[-3]+RC[-2]+RC[-1]"
      Next Cl
      .Replace "=xxxAifinal", "AIFinal", xlPart, , False, , False, False
   End With
End Sub
 
Upvote 0
Ok, how about
Code:
Sub LNG2013()
   Dim Cl As Range
   Dim UsdRws As Long
   
   UsdRws = Cells.Find("*", , , , xlByRows, xlPrevious, , , False).Row
   With Range("1:1")
      .Replace "Aifinal", "=xxxAIFinal", xlPart, , False, , False, False
      For Each Cl In .SpecialCells(xlFormulas, xlErrors)
         Cl.Offset(1).Resize(UsdRws - 1).FormulaR1C1 = "=RC[-4]+RC[-3]+RC[-2]+RC[-1]"
      Next Cl
      .Replace "=xxxAifinal", "AIFinal", xlPart, , False, , False, False
   End With
End Sub



Thank worked splendidly thank you sooo much!
Flawless Victory!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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