My goal is to have the result of:
11:29:30 AM United States 2,575,517 0.1046%
11:29:30 AM Japan 6,013,355 0.2442%
11:29:30 AM Hong Kong 669,088 0.0272%
update every time the data from wrksheet1 refreshes. However with the current VBA in my wrksheet it continues to grow row by row every time the data refreshes. I want three rows that are overwritten each time the data is refreshed. I do not want it to add additional rows. Here is the code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lRow As Long, lRow2 As Long, WF As WorksheetFunction
Set WF = Application.WorksheetFunction
If Not Application.Intersect(Target, Range("D")) Is Nothing Then
With Sheet2
lRow = .Range("A1").CurrentRegion.Rows.Count
.Cells(lRow, 1) = Now
.Cells(lRow, 2) = "United States"
.Cells(lRow, 3) = WF.SumIf(Sheet1.Range("Z:Z"), "USA", Sheet1.Range("D"))
.Cells(lRow, 4) = WF.SumIf(Sheet1.Range("Z:Z"), "USA", Sheet1.Range("D")) / Sheets("Notionals").Range("E16").Value
End With
With Sheet2
lRow2 = lRow + 1
.Cells(lRow2, 1) = Now
.Cells(lRow2, 2) = "Japan"
.Cells(lRow2, 3) = WF.SumIf(Sheet1.Range("Z:Z"), "JAP", Sheet1.Range("D"))
.Cells(lRow2, 4) = WF.SumIf(Sheet1.Range("Z:Z"), "JAP", Sheet1.Range("D")) / Sheets("Notionals").Range("E16").Value
End With
With Sheet2
lRow3 = lRow2 + 1
.Cells(lRow3, 1) = Now
.Cells(lRow3, 2) = "Hong Kong"
.Cells(lRow3, 3) = WF.SumIf(Sheet1.Range("Z:Z"), "HOK", Sheet1.Range("D"))
.Cells(lRow3, 4) = WF.SumIf(Sheet1.Range("Z:Z"), "HOK", Sheet1.Range("D")) / Sheets("Notionals").Range("E16").Value
End With
End If
Set WF = Nothing
End Sub
How can I adjust the current code to just overwrite the three rows every time the data is updated? any help would be much appreciated.
thanks
jumbo
11:29:30 AM United States 2,575,517 0.1046%
11:29:30 AM Japan 6,013,355 0.2442%
11:29:30 AM Hong Kong 669,088 0.0272%
update every time the data from wrksheet1 refreshes. However with the current VBA in my wrksheet it continues to grow row by row every time the data refreshes. I want three rows that are overwritten each time the data is refreshed. I do not want it to add additional rows. Here is the code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lRow As Long, lRow2 As Long, WF As WorksheetFunction
Set WF = Application.WorksheetFunction
If Not Application.Intersect(Target, Range("D")) Is Nothing Then
With Sheet2
lRow = .Range("A1").CurrentRegion.Rows.Count
.Cells(lRow, 1) = Now
.Cells(lRow, 2) = "United States"
.Cells(lRow, 3) = WF.SumIf(Sheet1.Range("Z:Z"), "USA", Sheet1.Range("D"))
.Cells(lRow, 4) = WF.SumIf(Sheet1.Range("Z:Z"), "USA", Sheet1.Range("D")) / Sheets("Notionals").Range("E16").Value
End With
With Sheet2
lRow2 = lRow + 1
.Cells(lRow2, 1) = Now
.Cells(lRow2, 2) = "Japan"
.Cells(lRow2, 3) = WF.SumIf(Sheet1.Range("Z:Z"), "JAP", Sheet1.Range("D"))
.Cells(lRow2, 4) = WF.SumIf(Sheet1.Range("Z:Z"), "JAP", Sheet1.Range("D")) / Sheets("Notionals").Range("E16").Value
End With
With Sheet2
lRow3 = lRow2 + 1
.Cells(lRow3, 1) = Now
.Cells(lRow3, 2) = "Hong Kong"
.Cells(lRow3, 3) = WF.SumIf(Sheet1.Range("Z:Z"), "HOK", Sheet1.Range("D"))
.Cells(lRow3, 4) = WF.SumIf(Sheet1.Range("Z:Z"), "HOK", Sheet1.Range("D")) / Sheets("Notionals").Range("E16").Value
End With
End If
Set WF = Nothing
End Sub
How can I adjust the current code to just overwrite the three rows every time the data is updated? any help would be much appreciated.
thanks
jumbo