keaveneydan
Board Regular
- Joined
- Apr 29, 2014
- Messages
- 144
Hi
I would like to create a change event macro that will update multiple formulas that pull data from various tabs on a file. The tabs are named with a single date.
So ideally when a certain master cell (Allocation!H2) is updated to the current date the macro will be prompted to update the range that contains formulas and update accordingly...so its and index match fomula based that has a variable being the tab name which is a date.
I have a range of dates in cells F4:AB4 and want the formula to go into F5:AB5, I can then fill that down to whatever row I want...that bit I can handle.
I have tried in vain to cobble something together but I am pretty sure it is horrible. Can anyone help or rather does anyone want to help
Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Worksheets("Allocation").Range("H2")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
Worksheets("Rating").Select
Dim TABNAMEDATE(2, 23) As String
Dim iCell As Range
Dim i As Integer
Dim n As Integer
Dim Wb As Workbook
TABNAMEDATE(0, 0) = Range("F4").Value
i = 0
n = 0
For Each iCell In Range("F4:AB4")
TABNAMEDATE(0, i) = iCell.Value
i = i + 1
Application.ScreenUpdating = False: Application.Calculation = xlCalculationManual
Dim cell As Range: On Error Resume Next
For Each cell In ActiveSheet.Range("F4:AB4").Cells
If cell <> "" Then cell.Offset(1, 0).Formula = "=INDEX('\\svr01\data\Market_Funds\Fund SEBF\[SEBF Portfolio.xlsx]" & TABNAMEDATE(i, 0) & "'!$A:$IV,MATCH($A5,'\\svr01\data\Market_Funds\Fund SEBF\[SEBF Portfolio.xlsx]" & TABNAMEDATE(i, 0) & "'!$A$1:$A$65536,FALSE),MATCH('\\svr01\data\Market_Funds\Fund SEBF\[SEBF Portfolio.xlsx]" & TABNAMEDATE(i, 0) & "'!$R$5,'\\svr01\data\Market_Funds\Fund SEBF\[SEBF Portfolio.xlsx]" & TABNAMEDATE(i, 0) & "'!$A$5:$IV$5,FALSE))"
Next cell
Application.Calculation = xlCalculationAutomatic
End Sub
I would like to create a change event macro that will update multiple formulas that pull data from various tabs on a file. The tabs are named with a single date.
So ideally when a certain master cell (Allocation!H2) is updated to the current date the macro will be prompted to update the range that contains formulas and update accordingly...so its and index match fomula based that has a variable being the tab name which is a date.
I have a range of dates in cells F4:AB4 and want the formula to go into F5:AB5, I can then fill that down to whatever row I want...that bit I can handle.
I have tried in vain to cobble something together but I am pretty sure it is horrible. Can anyone help or rather does anyone want to help
Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Worksheets("Allocation").Range("H2")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
Worksheets("Rating").Select
Dim TABNAMEDATE(2, 23) As String
Dim iCell As Range
Dim i As Integer
Dim n As Integer
Dim Wb As Workbook
TABNAMEDATE(0, 0) = Range("F4").Value
i = 0
n = 0
For Each iCell In Range("F4:AB4")
TABNAMEDATE(0, i) = iCell.Value
i = i + 1
Application.ScreenUpdating = False: Application.Calculation = xlCalculationManual
Dim cell As Range: On Error Resume Next
For Each cell In ActiveSheet.Range("F4:AB4").Cells
If cell <> "" Then cell.Offset(1, 0).Formula = "=INDEX('\\svr01\data\Market_Funds\Fund SEBF\[SEBF Portfolio.xlsx]" & TABNAMEDATE(i, 0) & "'!$A:$IV,MATCH($A5,'\\svr01\data\Market_Funds\Fund SEBF\[SEBF Portfolio.xlsx]" & TABNAMEDATE(i, 0) & "'!$A$1:$A$65536,FALSE),MATCH('\\svr01\data\Market_Funds\Fund SEBF\[SEBF Portfolio.xlsx]" & TABNAMEDATE(i, 0) & "'!$R$5,'\\svr01\data\Market_Funds\Fund SEBF\[SEBF Portfolio.xlsx]" & TABNAMEDATE(i, 0) & "'!$A$5:$IV$5,FALSE))"
Next cell
Application.Calculation = xlCalculationAutomatic
End Sub