Nititchandra77
New Member
- Joined
- Mar 22, 2024
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
This code was working but not working now and it's really slow.
Sub automate_200324_loop()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim CellValue As String, rs As Worksheet, p As Integer, q As Integer
Dim cellValue1 As String, wb As Workbook: Set wb = ActiveWorkbook
Dim startName As String: startName = " "
Dim counter As Integer: counter = 1
Dim lastrow As Long, lastRow2 As Long, LastRow3 As Long, LastRow4 As Long, rgdata As Range
Dim lRow As Long, lColumn As Long, n As Integer
'Activate the omb file
Worksheets("OMB file").Activate
lColumn = Range("a1").CurrentRegion.Columns.Count
For n = 1 To lColumn Step 2
Sheets("OMB file").Columns.Copy Destination:=Sheets("Input OMB").Columns(1)
Sheets("OMB file").Columns(n + 1).Copy Destination:=Sheets("Input OMB").Columns(2)
Worksheets("Input OMB").Activate
Worksheets("Input OMB").Range("A1:a1").Copy
CellValue = Range("A1:a1").Value
Worksheets("DATA DICTIONARY").Activate
Rows(1).Select
Selection.Find(What:=CellValue, After:=ActiveCell, _
LookIn:=xlFormulas2, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Select
ActiveCell.Offset(0, -1).Select
ActiveCell.Columns("A:B").EntireColumn.Select
Selection.Copy Destination:=Worksheets("Input CFW DD").Range("A1")
Application.CutCopyMode = False
Sheets("Final output").Range("a:f").Copy
Sheets.Add After:=ActiveSheet
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Name = ActiveSheet.Range("e1")
Worksheets("OMB file").Range("ak1").Copy Destination:=ActiveSheet.Range("h1")
'1st Conditional format cells
ActiveSheet.Range("A1,A:A,d:d").Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
'Second conditional format
ActiveSheet.Range("b1,b:b,e:e").Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
ActiveWorkbook.Save
lastrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).row
For p = 2 To lastrow
ActiveSheet.Select
'If Cells(p, 1).Interior.ColorIndex = -4142 Then
If Cells(p, 1).DisplayFormat.Interior.Color = 13551615 Then
Cells(p, 1).Offset(0, 2) = " "
Else: Cells(p, 1).Offset(0, 2) = " Update code/ Add new code and value"
End If
Next p
'170224
lastRow2 = ActiveSheet.Cells(ActiveSheet.Rows.Count, "d").End(xlUp).row
For q = 2 To lastRow2
ActiveSheet.Select
'If Cells(p, 1).Interior.ColorIndex = -4142 Then
If Cells(q, 4).DisplayFormat.Interior.Color = 13551615 Then
Cells(q, 4).Offset(0, 2) = " "
Else: Cells(q, 4).Offset(0, 2) = " Archive"
End If
Next q
Next n
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub automate_200324_loop()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim CellValue As String, rs As Worksheet, p As Integer, q As Integer
Dim cellValue1 As String, wb As Workbook: Set wb = ActiveWorkbook
Dim startName As String: startName = " "
Dim counter As Integer: counter = 1
Dim lastrow As Long, lastRow2 As Long, LastRow3 As Long, LastRow4 As Long, rgdata As Range
Dim lRow As Long, lColumn As Long, n As Integer
'Activate the omb file
Worksheets("OMB file").Activate
lColumn = Range("a1").CurrentRegion.Columns.Count
For n = 1 To lColumn Step 2
Sheets("OMB file").Columns.Copy Destination:=Sheets("Input OMB").Columns(1)
Sheets("OMB file").Columns(n + 1).Copy Destination:=Sheets("Input OMB").Columns(2)
Worksheets("Input OMB").Activate
Worksheets("Input OMB").Range("A1:a1").Copy
CellValue = Range("A1:a1").Value
Worksheets("DATA DICTIONARY").Activate
Rows(1).Select
Selection.Find(What:=CellValue, After:=ActiveCell, _
LookIn:=xlFormulas2, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Select
ActiveCell.Offset(0, -1).Select
ActiveCell.Columns("A:B").EntireColumn.Select
Selection.Copy Destination:=Worksheets("Input CFW DD").Range("A1")
Application.CutCopyMode = False
Sheets("Final output").Range("a:f").Copy
Sheets.Add After:=ActiveSheet
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Name = ActiveSheet.Range("e1")
Worksheets("OMB file").Range("ak1").Copy Destination:=ActiveSheet.Range("h1")
'1st Conditional format cells
ActiveSheet.Range("A1,A:A,d:d").Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
'Second conditional format
ActiveSheet.Range("b1,b:b,e:e").Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
ActiveWorkbook.Save
lastrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).row
For p = 2 To lastrow
ActiveSheet.Select
'If Cells(p, 1).Interior.ColorIndex = -4142 Then
If Cells(p, 1).DisplayFormat.Interior.Color = 13551615 Then
Cells(p, 1).Offset(0, 2) = " "
Else: Cells(p, 1).Offset(0, 2) = " Update code/ Add new code and value"
End If
Next p
'170224
lastRow2 = ActiveSheet.Cells(ActiveSheet.Rows.Count, "d").End(xlUp).row
For q = 2 To lastRow2
ActiveSheet.Select
'If Cells(p, 1).Interior.ColorIndex = -4142 Then
If Cells(q, 4).DisplayFormat.Interior.Color = 13551615 Then
Cells(q, 4).Offset(0, 2) = " "
Else: Cells(q, 4).Offset(0, 2) = " Archive"
End If
Next q
Next n
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub