Improving speed of data clean process in vba





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0












$begingroup$


My does exactly what I want it to. However, being relatively new to VBA I feel it could be a lot more efficient - namely I think I have overused loops and worksheet functions which are slowing it down. At the moment it takes around 3 minutes for ~15k rows of data.



At the moment it's more of a combination of separate steps joined together so it doesn't flow nicely, rather for each steps it iterates through every row which, while it gets the job done, is frustratingly inefficient.



At the moment I am trying to remove the loops perhaps using Range objects instead, but I would really appreciate any pointers in the right direction.



Sub RunDataClean_Click()
With Sheets("Data")
'ensures code only loops through rows with data and not full worksheet
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
endrow = .Cells.Find(What:="*", _
After:=.Range("A4"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
endrow = 4
End If
End With

Application.ScreenUpdating = False

Dim i As Long

'Checks another sheet to see if we have the cleaned customer name on file
For i = 5 To endrow

'does a vlookup in CDM file
Acc = Application.Cells(i, 5)
Cname = Application.Cells(i, 4)

Acname = Application.VLookup(Acc, Sheet3.Range("D2:F315104"), 3, False)
If IsError(Acname) Then
Cells(i, 32).Value = ""
Else
Cells(i, 32).Value = Acname
End If

Map = Application.VLookup(Acc, Sheet3.Range("C2:F315104"), 4, False)
If IsEmpty(Cells(i, 32)) Then
If IsError(Map) Then
Cells(i, 32).Value = ""
Else
Cells(i, 32).Value = Map
End If
End If

FXid = Application.VLookup(Acc, Sheet3.Range("B2:F315104"), 5, False)
If IsEmpty(Cells(i, 32)) Then
If IsError(FXid) Then
Cells(i, 32).Value = ""
Else
Cells(i, 32).Value = FXid
End If
End If

FXP = Application.VLookup(Cname, Sheet3.Range("A2:F315104"), 6, False)
If IsEmpty(Cells(i, 32)) Then
If IsError(FXP) Then
Cells(i, 32).Value = ""
Else
Cells(i, 32).Value = FXP
End If
End If

LkpName = Application.VLookup(Cname, Sheet3.Range("F2:F315104"), 1, False)
If IsEmpty(Cells(i, 32)) Then
If IsError(LkpName) Then
Cells(i, 32).Value = ""
Else
Cells(i, 32).Value = LkpName
End If
End If

If IsEmpty(Cells(i, 32)) Then
Cells(i, 32).Value = Cells(i, 4).Value
End If

Next i
For i = 5 To endrow

Cells(i, 28).Value = Cells(i, 3).Value & Cells(i, 5).Value
Length = Len(Cells(i, 28))
Cells(i, 29).Value = Length
Cells(i, 31).Value = Cells(i, 4).Value

'does a vlookup in CDM file (CDM)
Acc = Application.Cells(i, 28)
BP = Application.VLookup(Acc, Sheet3.Range("E2:G315104"), 3, False)
If IsError(BP) Then
Cells(i, 30).Value = ""
Else
Cells(i, 30).Value = BP
End If

'assigns B or P based on payment details (Business_Personal)
If Cells(i, 12).Value = "N" Then
Cells(i, 24).Value = "B"
ElseIf Cells(i, 30).Value = "Business" Then
Cells(i, 24).Value = "B"
ElseIf Cells(i, 30).Value = "Personal" Then
Cells(i, 24).Value = "P"
ElseIf Cells(i, 12).Value = "Y" Then
Cells(i, 24).Value = "P"
ElseIf InStr(1, Cells(i, 32), "LTD") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "LIMITED") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "MANAGE") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "BUSINESS") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "CONSULT") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "INTERNATIONAL") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "T/A") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "TECH") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "CLUB") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "OIL") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "SERVICE") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "SOLICITOR") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf InStr(1, Cells(i, 32), "CORP") <> 0 Then
Cells(i, 24).Value = "B"
ElseIf Left(Cells(i, 5).Value, 3) = "999" Then
Cells(i, 24).Value = "P"
End If
Next i

'Week_Of_Year
For i = 5 To endrow
WeekNo = Application.Cells(i, 1)
WeekNumba = Application.WeekNum(WeekNo)
Cells(i, 21).Value = WeekNumba
Next i

'Deal_Channel concatenation
For i = 5 To endrow
Cells(i, 22).Value = Cells(i, 6).Value & Cells(i, 13).Value & Cells(i, 17).Value
Next i

'Deal_Source_System
For i = 5 To endrow
DealSS = Application.Cells(i, 22)

Deal_Source = Application.VLookup(DealSS, Sheet4.Range("F2:H354"), 3, False)
If IsError(Deal_Source) Then
Cells(i, 23).Value = "#N/A"
Else
Cells(i, 23).Value = Deal_Source
End If
Next i

'Reporting_Quarter (only worked for type double)
'does a lookup in calendar tab to return reporting quarter - could move this to Access
For i = 5 To endrow
qdate = Cells(i, 1)
qlkp = Application.VLookup(CDbl(qdate), Sheet5.Range("A1:C500"), 3, False)
Cells(i, 26).Value = qlkp
Next i

'copies any #N/A deal channel to lookup tables and then sets deal source to map
lastrow = Sheet4.Cells(Rows.Count, "F").End(xlUp).Row + 1
With Sheet1.Range("W5:W" & endrow)
Set DS = .Find(What:="#N/A", LookIn:=xlValues)
If Not DS Is Nothing Then
firstAddress = DS.Address
Do
DS.Offset(, -1).Copy
Sheet3.Range("F" & lastrow).PasteSpecial xlPasteValues
DS.Value = "Map"
Set DS = .FindNext(DS)
lastrow = lastrow + 1
Loop While Not DS Is Nothing
End If
End With

Application.ScreenUpdating = True
End Sub








share







New contributor




edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



















    0












    $begingroup$


    My does exactly what I want it to. However, being relatively new to VBA I feel it could be a lot more efficient - namely I think I have overused loops and worksheet functions which are slowing it down. At the moment it takes around 3 minutes for ~15k rows of data.



    At the moment it's more of a combination of separate steps joined together so it doesn't flow nicely, rather for each steps it iterates through every row which, while it gets the job done, is frustratingly inefficient.



    At the moment I am trying to remove the loops perhaps using Range objects instead, but I would really appreciate any pointers in the right direction.



    Sub RunDataClean_Click()
    With Sheets("Data")
    'ensures code only loops through rows with data and not full worksheet
    If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
    endrow = .Cells.Find(What:="*", _
    After:=.Range("A4"), _
    Lookat:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Row
    Else
    endrow = 4
    End If
    End With

    Application.ScreenUpdating = False

    Dim i As Long

    'Checks another sheet to see if we have the cleaned customer name on file
    For i = 5 To endrow

    'does a vlookup in CDM file
    Acc = Application.Cells(i, 5)
    Cname = Application.Cells(i, 4)

    Acname = Application.VLookup(Acc, Sheet3.Range("D2:F315104"), 3, False)
    If IsError(Acname) Then
    Cells(i, 32).Value = ""
    Else
    Cells(i, 32).Value = Acname
    End If

    Map = Application.VLookup(Acc, Sheet3.Range("C2:F315104"), 4, False)
    If IsEmpty(Cells(i, 32)) Then
    If IsError(Map) Then
    Cells(i, 32).Value = ""
    Else
    Cells(i, 32).Value = Map
    End If
    End If

    FXid = Application.VLookup(Acc, Sheet3.Range("B2:F315104"), 5, False)
    If IsEmpty(Cells(i, 32)) Then
    If IsError(FXid) Then
    Cells(i, 32).Value = ""
    Else
    Cells(i, 32).Value = FXid
    End If
    End If

    FXP = Application.VLookup(Cname, Sheet3.Range("A2:F315104"), 6, False)
    If IsEmpty(Cells(i, 32)) Then
    If IsError(FXP) Then
    Cells(i, 32).Value = ""
    Else
    Cells(i, 32).Value = FXP
    End If
    End If

    LkpName = Application.VLookup(Cname, Sheet3.Range("F2:F315104"), 1, False)
    If IsEmpty(Cells(i, 32)) Then
    If IsError(LkpName) Then
    Cells(i, 32).Value = ""
    Else
    Cells(i, 32).Value = LkpName
    End If
    End If

    If IsEmpty(Cells(i, 32)) Then
    Cells(i, 32).Value = Cells(i, 4).Value
    End If

    Next i
    For i = 5 To endrow

    Cells(i, 28).Value = Cells(i, 3).Value & Cells(i, 5).Value
    Length = Len(Cells(i, 28))
    Cells(i, 29).Value = Length
    Cells(i, 31).Value = Cells(i, 4).Value

    'does a vlookup in CDM file (CDM)
    Acc = Application.Cells(i, 28)
    BP = Application.VLookup(Acc, Sheet3.Range("E2:G315104"), 3, False)
    If IsError(BP) Then
    Cells(i, 30).Value = ""
    Else
    Cells(i, 30).Value = BP
    End If

    'assigns B or P based on payment details (Business_Personal)
    If Cells(i, 12).Value = "N" Then
    Cells(i, 24).Value = "B"
    ElseIf Cells(i, 30).Value = "Business" Then
    Cells(i, 24).Value = "B"
    ElseIf Cells(i, 30).Value = "Personal" Then
    Cells(i, 24).Value = "P"
    ElseIf Cells(i, 12).Value = "Y" Then
    Cells(i, 24).Value = "P"
    ElseIf InStr(1, Cells(i, 32), "LTD") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "LIMITED") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "MANAGE") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "BUSINESS") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "CONSULT") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "INTERNATIONAL") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "T/A") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "TECH") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "CLUB") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "OIL") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "SERVICE") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "SOLICITOR") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf InStr(1, Cells(i, 32), "CORP") <> 0 Then
    Cells(i, 24).Value = "B"
    ElseIf Left(Cells(i, 5).Value, 3) = "999" Then
    Cells(i, 24).Value = "P"
    End If
    Next i

    'Week_Of_Year
    For i = 5 To endrow
    WeekNo = Application.Cells(i, 1)
    WeekNumba = Application.WeekNum(WeekNo)
    Cells(i, 21).Value = WeekNumba
    Next i

    'Deal_Channel concatenation
    For i = 5 To endrow
    Cells(i, 22).Value = Cells(i, 6).Value & Cells(i, 13).Value & Cells(i, 17).Value
    Next i

    'Deal_Source_System
    For i = 5 To endrow
    DealSS = Application.Cells(i, 22)

    Deal_Source = Application.VLookup(DealSS, Sheet4.Range("F2:H354"), 3, False)
    If IsError(Deal_Source) Then
    Cells(i, 23).Value = "#N/A"
    Else
    Cells(i, 23).Value = Deal_Source
    End If
    Next i

    'Reporting_Quarter (only worked for type double)
    'does a lookup in calendar tab to return reporting quarter - could move this to Access
    For i = 5 To endrow
    qdate = Cells(i, 1)
    qlkp = Application.VLookup(CDbl(qdate), Sheet5.Range("A1:C500"), 3, False)
    Cells(i, 26).Value = qlkp
    Next i

    'copies any #N/A deal channel to lookup tables and then sets deal source to map
    lastrow = Sheet4.Cells(Rows.Count, "F").End(xlUp).Row + 1
    With Sheet1.Range("W5:W" & endrow)
    Set DS = .Find(What:="#N/A", LookIn:=xlValues)
    If Not DS Is Nothing Then
    firstAddress = DS.Address
    Do
    DS.Offset(, -1).Copy
    Sheet3.Range("F" & lastrow).PasteSpecial xlPasteValues
    DS.Value = "Map"
    Set DS = .FindNext(DS)
    lastrow = lastrow + 1
    Loop While Not DS Is Nothing
    End If
    End With

    Application.ScreenUpdating = True
    End Sub








    share







    New contributor




    edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      0












      0








      0





      $begingroup$


      My does exactly what I want it to. However, being relatively new to VBA I feel it could be a lot more efficient - namely I think I have overused loops and worksheet functions which are slowing it down. At the moment it takes around 3 minutes for ~15k rows of data.



      At the moment it's more of a combination of separate steps joined together so it doesn't flow nicely, rather for each steps it iterates through every row which, while it gets the job done, is frustratingly inefficient.



      At the moment I am trying to remove the loops perhaps using Range objects instead, but I would really appreciate any pointers in the right direction.



      Sub RunDataClean_Click()
      With Sheets("Data")
      'ensures code only loops through rows with data and not full worksheet
      If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
      endrow = .Cells.Find(What:="*", _
      After:=.Range("A4"), _
      Lookat:=xlPart, _
      LookIn:=xlFormulas, _
      SearchOrder:=xlByRows, _
      SearchDirection:=xlPrevious, _
      MatchCase:=False).Row
      Else
      endrow = 4
      End If
      End With

      Application.ScreenUpdating = False

      Dim i As Long

      'Checks another sheet to see if we have the cleaned customer name on file
      For i = 5 To endrow

      'does a vlookup in CDM file
      Acc = Application.Cells(i, 5)
      Cname = Application.Cells(i, 4)

      Acname = Application.VLookup(Acc, Sheet3.Range("D2:F315104"), 3, False)
      If IsError(Acname) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = Acname
      End If

      Map = Application.VLookup(Acc, Sheet3.Range("C2:F315104"), 4, False)
      If IsEmpty(Cells(i, 32)) Then
      If IsError(Map) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = Map
      End If
      End If

      FXid = Application.VLookup(Acc, Sheet3.Range("B2:F315104"), 5, False)
      If IsEmpty(Cells(i, 32)) Then
      If IsError(FXid) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = FXid
      End If
      End If

      FXP = Application.VLookup(Cname, Sheet3.Range("A2:F315104"), 6, False)
      If IsEmpty(Cells(i, 32)) Then
      If IsError(FXP) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = FXP
      End If
      End If

      LkpName = Application.VLookup(Cname, Sheet3.Range("F2:F315104"), 1, False)
      If IsEmpty(Cells(i, 32)) Then
      If IsError(LkpName) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = LkpName
      End If
      End If

      If IsEmpty(Cells(i, 32)) Then
      Cells(i, 32).Value = Cells(i, 4).Value
      End If

      Next i
      For i = 5 To endrow

      Cells(i, 28).Value = Cells(i, 3).Value & Cells(i, 5).Value
      Length = Len(Cells(i, 28))
      Cells(i, 29).Value = Length
      Cells(i, 31).Value = Cells(i, 4).Value

      'does a vlookup in CDM file (CDM)
      Acc = Application.Cells(i, 28)
      BP = Application.VLookup(Acc, Sheet3.Range("E2:G315104"), 3, False)
      If IsError(BP) Then
      Cells(i, 30).Value = ""
      Else
      Cells(i, 30).Value = BP
      End If

      'assigns B or P based on payment details (Business_Personal)
      If Cells(i, 12).Value = "N" Then
      Cells(i, 24).Value = "B"
      ElseIf Cells(i, 30).Value = "Business" Then
      Cells(i, 24).Value = "B"
      ElseIf Cells(i, 30).Value = "Personal" Then
      Cells(i, 24).Value = "P"
      ElseIf Cells(i, 12).Value = "Y" Then
      Cells(i, 24).Value = "P"
      ElseIf InStr(1, Cells(i, 32), "LTD") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "LIMITED") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "MANAGE") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "BUSINESS") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "CONSULT") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "INTERNATIONAL") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "T/A") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "TECH") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "CLUB") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "OIL") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "SERVICE") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "SOLICITOR") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "CORP") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf Left(Cells(i, 5).Value, 3) = "999" Then
      Cells(i, 24).Value = "P"
      End If
      Next i

      'Week_Of_Year
      For i = 5 To endrow
      WeekNo = Application.Cells(i, 1)
      WeekNumba = Application.WeekNum(WeekNo)
      Cells(i, 21).Value = WeekNumba
      Next i

      'Deal_Channel concatenation
      For i = 5 To endrow
      Cells(i, 22).Value = Cells(i, 6).Value & Cells(i, 13).Value & Cells(i, 17).Value
      Next i

      'Deal_Source_System
      For i = 5 To endrow
      DealSS = Application.Cells(i, 22)

      Deal_Source = Application.VLookup(DealSS, Sheet4.Range("F2:H354"), 3, False)
      If IsError(Deal_Source) Then
      Cells(i, 23).Value = "#N/A"
      Else
      Cells(i, 23).Value = Deal_Source
      End If
      Next i

      'Reporting_Quarter (only worked for type double)
      'does a lookup in calendar tab to return reporting quarter - could move this to Access
      For i = 5 To endrow
      qdate = Cells(i, 1)
      qlkp = Application.VLookup(CDbl(qdate), Sheet5.Range("A1:C500"), 3, False)
      Cells(i, 26).Value = qlkp
      Next i

      'copies any #N/A deal channel to lookup tables and then sets deal source to map
      lastrow = Sheet4.Cells(Rows.Count, "F").End(xlUp).Row + 1
      With Sheet1.Range("W5:W" & endrow)
      Set DS = .Find(What:="#N/A", LookIn:=xlValues)
      If Not DS Is Nothing Then
      firstAddress = DS.Address
      Do
      DS.Offset(, -1).Copy
      Sheet3.Range("F" & lastrow).PasteSpecial xlPasteValues
      DS.Value = "Map"
      Set DS = .FindNext(DS)
      lastrow = lastrow + 1
      Loop While Not DS Is Nothing
      End If
      End With

      Application.ScreenUpdating = True
      End Sub








      share







      New contributor




      edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      My does exactly what I want it to. However, being relatively new to VBA I feel it could be a lot more efficient - namely I think I have overused loops and worksheet functions which are slowing it down. At the moment it takes around 3 minutes for ~15k rows of data.



      At the moment it's more of a combination of separate steps joined together so it doesn't flow nicely, rather for each steps it iterates through every row which, while it gets the job done, is frustratingly inefficient.



      At the moment I am trying to remove the loops perhaps using Range objects instead, but I would really appreciate any pointers in the right direction.



      Sub RunDataClean_Click()
      With Sheets("Data")
      'ensures code only loops through rows with data and not full worksheet
      If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
      endrow = .Cells.Find(What:="*", _
      After:=.Range("A4"), _
      Lookat:=xlPart, _
      LookIn:=xlFormulas, _
      SearchOrder:=xlByRows, _
      SearchDirection:=xlPrevious, _
      MatchCase:=False).Row
      Else
      endrow = 4
      End If
      End With

      Application.ScreenUpdating = False

      Dim i As Long

      'Checks another sheet to see if we have the cleaned customer name on file
      For i = 5 To endrow

      'does a vlookup in CDM file
      Acc = Application.Cells(i, 5)
      Cname = Application.Cells(i, 4)

      Acname = Application.VLookup(Acc, Sheet3.Range("D2:F315104"), 3, False)
      If IsError(Acname) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = Acname
      End If

      Map = Application.VLookup(Acc, Sheet3.Range("C2:F315104"), 4, False)
      If IsEmpty(Cells(i, 32)) Then
      If IsError(Map) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = Map
      End If
      End If

      FXid = Application.VLookup(Acc, Sheet3.Range("B2:F315104"), 5, False)
      If IsEmpty(Cells(i, 32)) Then
      If IsError(FXid) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = FXid
      End If
      End If

      FXP = Application.VLookup(Cname, Sheet3.Range("A2:F315104"), 6, False)
      If IsEmpty(Cells(i, 32)) Then
      If IsError(FXP) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = FXP
      End If
      End If

      LkpName = Application.VLookup(Cname, Sheet3.Range("F2:F315104"), 1, False)
      If IsEmpty(Cells(i, 32)) Then
      If IsError(LkpName) Then
      Cells(i, 32).Value = ""
      Else
      Cells(i, 32).Value = LkpName
      End If
      End If

      If IsEmpty(Cells(i, 32)) Then
      Cells(i, 32).Value = Cells(i, 4).Value
      End If

      Next i
      For i = 5 To endrow

      Cells(i, 28).Value = Cells(i, 3).Value & Cells(i, 5).Value
      Length = Len(Cells(i, 28))
      Cells(i, 29).Value = Length
      Cells(i, 31).Value = Cells(i, 4).Value

      'does a vlookup in CDM file (CDM)
      Acc = Application.Cells(i, 28)
      BP = Application.VLookup(Acc, Sheet3.Range("E2:G315104"), 3, False)
      If IsError(BP) Then
      Cells(i, 30).Value = ""
      Else
      Cells(i, 30).Value = BP
      End If

      'assigns B or P based on payment details (Business_Personal)
      If Cells(i, 12).Value = "N" Then
      Cells(i, 24).Value = "B"
      ElseIf Cells(i, 30).Value = "Business" Then
      Cells(i, 24).Value = "B"
      ElseIf Cells(i, 30).Value = "Personal" Then
      Cells(i, 24).Value = "P"
      ElseIf Cells(i, 12).Value = "Y" Then
      Cells(i, 24).Value = "P"
      ElseIf InStr(1, Cells(i, 32), "LTD") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "LIMITED") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "MANAGE") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "BUSINESS") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "CONSULT") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "INTERNATIONAL") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "T/A") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "TECH") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "CLUB") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "OIL") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "SERVICE") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "SOLICITOR") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf InStr(1, Cells(i, 32), "CORP") <> 0 Then
      Cells(i, 24).Value = "B"
      ElseIf Left(Cells(i, 5).Value, 3) = "999" Then
      Cells(i, 24).Value = "P"
      End If
      Next i

      'Week_Of_Year
      For i = 5 To endrow
      WeekNo = Application.Cells(i, 1)
      WeekNumba = Application.WeekNum(WeekNo)
      Cells(i, 21).Value = WeekNumba
      Next i

      'Deal_Channel concatenation
      For i = 5 To endrow
      Cells(i, 22).Value = Cells(i, 6).Value & Cells(i, 13).Value & Cells(i, 17).Value
      Next i

      'Deal_Source_System
      For i = 5 To endrow
      DealSS = Application.Cells(i, 22)

      Deal_Source = Application.VLookup(DealSS, Sheet4.Range("F2:H354"), 3, False)
      If IsError(Deal_Source) Then
      Cells(i, 23).Value = "#N/A"
      Else
      Cells(i, 23).Value = Deal_Source
      End If
      Next i

      'Reporting_Quarter (only worked for type double)
      'does a lookup in calendar tab to return reporting quarter - could move this to Access
      For i = 5 To endrow
      qdate = Cells(i, 1)
      qlkp = Application.VLookup(CDbl(qdate), Sheet5.Range("A1:C500"), 3, False)
      Cells(i, 26).Value = qlkp
      Next i

      'copies any #N/A deal channel to lookup tables and then sets deal source to map
      lastrow = Sheet4.Cells(Rows.Count, "F").End(xlUp).Row + 1
      With Sheet1.Range("W5:W" & endrow)
      Set DS = .Find(What:="#N/A", LookIn:=xlValues)
      If Not DS Is Nothing Then
      firstAddress = DS.Address
      Do
      DS.Offset(, -1).Copy
      Sheet3.Range("F" & lastrow).PasteSpecial xlPasteValues
      DS.Value = "Map"
      Set DS = .FindNext(DS)
      lastrow = lastrow + 1
      Loop While Not DS Is Nothing
      End If
      End With

      Application.ScreenUpdating = True
      End Sub






      performance vba excel





      share







      New contributor




      edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 8 mins ago









      edevedev

      12




      12




      New contributor




      edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      edev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          edev is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217553%2fimproving-speed-of-data-clean-process-in-vba%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          edev is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          edev is a new contributor. Be nice, and check out our Code of Conduct.













          edev is a new contributor. Be nice, and check out our Code of Conduct.












          edev is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217553%2fimproving-speed-of-data-clean-process-in-vba%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар