NiiBoi_Gifted
New Member
- Joined
- Jun 23, 2024
- Messages
- 1
- Office Version
- 2013
- Platform
- Windows
Can you please help with this macro? It is an update macro but any time I run it, it takes a long time to update
Sub UpdateAmountBasedOnACCT()
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
Dim primaryKey As String
Dim lookupRange As Range
Dim cell As Range
Dim FoundCell As Range
' Set the worksheets
Set wsSource = ThisWorkbook.Sheets("Search")
Set wsTarget = ThisWorkbook.Sheets("DATA")
' Define the lookup range in DATA
Set lookupRange = wsTarget.Range("B:N") ' Adjust the range as necessary
' Loop through each cell in Search where ACCT are located
For Each cell In wsTarget.Range("A:G") ' Adjust the range as necessary
If Not IsEmpty(cell.Value) Then
primaryKey = Sheet1.Range("B7")
' Find the ACCT in DATA
Set FoundCell = lookupRange.Columns(1).Find(What:=primaryKey, LookIn:=xlValues, LookAt:=xlWhole)
' If found, update the corresponding amount in DATA
If Not FoundCell Is Nothing Then
wsTarget.Cells(FoundCell.Row, 16).Value = Sheet1.Range("B13")
wsTarget.Cells(FoundCell.Row, 18).Value = Sheet1.Range("E13")
wsTarget.Cells(FoundCell.Row, 17).Value = Sheet1.Range("G13")
wsTarget.Cells(FoundCell.Row, 19).Value = Sheet1.Range("B14")
wsTarget.Cells(FoundCell.Row, 20).Value = Sheet1.Range("E14")
wsTarget.Cells(FoundCell.Row, 21).Value = Sheet1.Range("G14")
wsTarget.Cells(FoundCell.Row, 22).Value = Sheet1.Range("E15")
wsTarget.Cells(FoundCell.Row, 23).Value = Sheet1.Range("B15")
wsTarget.Cells(FoundCell.Row, 24).Value = Sheet1.Range("G15")
End If
End If
Next cell
MsgBox "Update complete!"
End Sub
Sub UpdateAmountBasedOnACCT()
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
Dim primaryKey As String
Dim lookupRange As Range
Dim cell As Range
Dim FoundCell As Range
' Set the worksheets
Set wsSource = ThisWorkbook.Sheets("Search")
Set wsTarget = ThisWorkbook.Sheets("DATA")
' Define the lookup range in DATA
Set lookupRange = wsTarget.Range("B:N") ' Adjust the range as necessary
' Loop through each cell in Search where ACCT are located
For Each cell In wsTarget.Range("A:G") ' Adjust the range as necessary
If Not IsEmpty(cell.Value) Then
primaryKey = Sheet1.Range("B7")
' Find the ACCT in DATA
Set FoundCell = lookupRange.Columns(1).Find(What:=primaryKey, LookIn:=xlValues, LookAt:=xlWhole)
' If found, update the corresponding amount in DATA
If Not FoundCell Is Nothing Then
wsTarget.Cells(FoundCell.Row, 16).Value = Sheet1.Range("B13")
wsTarget.Cells(FoundCell.Row, 18).Value = Sheet1.Range("E13")
wsTarget.Cells(FoundCell.Row, 17).Value = Sheet1.Range("G13")
wsTarget.Cells(FoundCell.Row, 19).Value = Sheet1.Range("B14")
wsTarget.Cells(FoundCell.Row, 20).Value = Sheet1.Range("E14")
wsTarget.Cells(FoundCell.Row, 21).Value = Sheet1.Range("G14")
wsTarget.Cells(FoundCell.Row, 22).Value = Sheet1.Range("E15")
wsTarget.Cells(FoundCell.Row, 23).Value = Sheet1.Range("B15")
wsTarget.Cells(FoundCell.Row, 24).Value = Sheet1.Range("G15")
End If
End If
Next cell
MsgBox "Update complete!"
End Sub