Advertisement
Guest User

Untitled

a guest
Oct 11th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub locationFillDown()
  2.  
  3.     'Initialization
  4.    Dim test, prod As Worksheet
  5.     Set prod = Sheets("SBL3N Production")
  6.     Set test = Sheets("SBL3N Test Environment")
  7.  
  8.     Application.ScreenUpdating = False
  9.  
  10.     'Msgbox
  11.    MsgBox ("The process of populating locations takes a few moments. Any line items with no location will be blank.")
  12.    
  13.     'Set prod Locations
  14.    
  15.     With prod
  16.         Dim prodLastRow As Integer
  17.         prodLastRow = .Range("M" & Rows.Count).End(xlUp).Row 'Used Column M bc it will always be populated
  18.    End With
  19.    
  20.     prod.Activate
  21.     Range("V2").Value = "=IF(IF(LEN(P2)=0,E2,LEFT(P2,4))=0,99999,IF(LEN(P2)=0,E2,LEFT(P2,4)))"
  22.     Range("V2:V" & prodLastRow).FillDown
  23.    
  24.     For Each prodCell In Range("V2:V" & prodLastRow)
  25.         If prodCell.Value = 99999 Then
  26.             prodCell.ClearContents
  27.         End If
  28.     Next prodCell
  29.    
  30.    
  31.     'Set test Locations
  32.    
  33.     With test
  34.         Dim testLastRow As Integer
  35.         testLastRow = .Range("C" & Rows.Count).End(xlUp).Row 'Used col C bc it will always be populated
  36.    End With
  37.    
  38.     test.Activate
  39.     Range("Q2").Value = "=IF(AND(ISBLANK(J2),ISBLANK(K2)),99999,IF(LEN(J2)=0,K2,LEFT(J2,4)))"
  40.     Range("Q2:Q" & testLastRow).FillDown
  41.    
  42.     For Each testCell In Range("Q2:Q" & testLastRow)
  43.         If testCell.Value = 99999 Then
  44.             testCell.ClearContents
  45.         End If
  46.     Next testCell
  47.  
  48.     Application.ScreenUpdating = True
  49.    
  50. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement