Sub DataTranspose_Optimized_027()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.DisplayStatusBar = True
Dim netSalaryColumn As Long
Dim wsName As String
wsName = "Financial Account Codes"
On Error Resume Next
If Evaluate("ISREF('" & wsName & "_Temp'!A1)") Then
Sheets(wsName & "_Temp").Cells.Copy Destination:=Sheets(wsName).Cells
Sheets(wsName & "_Temp").Delete
End If
On Error GoTo 0
Sheets(wsName).Copy After:=Sheets(wsName)
ActiveSheet.Name = wsName & "_Temp"
On Error Resume Next
Sheets("Pay Summary").Delete
On Error GoTo 0
Sheets("Source Data").Copy After:=Sheets("Source Data")
ActiveSheet.Name = "Pay Summary"
With ThisWorkbook.Sheets("Pay Summary").Rows(1)
netSalaryColumn = .Find("NET SALARY", , , xlWhole).Column
End With
If netSalaryColumn > 0 Then
ThisWorkbook.Sheets("Pay Summary").Range(Columns(netSalaryColumn + 1), Columns(Columns.Count)).Delete
End If
Set FinAccCodes = ThisWorkbook.Sheets("Financial Account Codes")
With FinAccCodes
.AutoFilterMode = False
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("A1:A" & lastRow).AutoFilter Field:=1, Criteria1:="<>027"
.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
.AutoFilterMode = False
End With
Dim R As Range, Vin As Variant, Vrw As Variant, Vout As Variant, i As Long, NxRw As Long
Set Wk = ThisWorkbook.Sheets("WS")
Set Srk = ThisWorkbook.Sheets("Pay Summary")
timetaken = Now()
For Each ws In ActiveWorkbook.Worksheets
If ws.AutoFilterMode = True Then
ws.AutoFilterMode = False
End If
Next ws
Wk.UsedRange.Clear
Enty.UsedRange.Offset(1).Clear
Dim arr As Variant
With Srk.Range("M1", Srk.Cells(Srk.Rows.Count, "M").End(xlUp))
.Value = Application.Trim(.Value)
End With
lastCol = Srk.Cells(1, Columns.Count).End(xlToLeft).Column
ColumnLetter = Split(Srk.Cells(1, lastCol).Address, "$")(1)
With Srk.Rows(1)
workLocationColumn = .Find("Work Location", , , xlWhole).Column
End With
lastRow = Srk.Cells(Srk.Rows.Count, "A").End(xlUp).Row
With Srk
.Columns("N").Insert Shift:=xlToRight
.Range("N1").Value = "x"
.Range("N2:N" & lastRow).FormulaR1C1 = "=VLOOKUP(RC[-1],'Site Details'!C[-13]:C[-12],2,0)"
On Error Resume Next
.Range("A1:N" & lastRow).AutoFilter Field:=14, Criteria1:="<>027", Operator:=xlFilterValues
If Application.WorksheetFunction.Subtotal(103, .Range("N1:N" & lastRow)) > 1 Then
.Range("N2:N" & lastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
.AutoFilterMode = False
On Error GoTo 0
End With
Srk.Columns("N").Delete
Wk.Range("A1:A" & lastCol).Value = WorksheetFunction.Transpose(Srk.Range("A1", ColumnLetter & lastCol))
Set R = Srk.Range("A1").CurrentRegion
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
lchkw = Srk.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To UBound(Vin)
If i Mod 1 <> 1 Then
Vrw = R.Rows(i).Value
Vout = Application.Transpose(Vrw)
NxRw = IIf(IsEmpty(Wk.Range("DY1")), 1, Wk.Range("DY" & Rows.Count).End(xlUp).Row + 1)
Wk.Range("B" & NxRw).Resize(UBound(Vrw, 2), 1).Value = Vout
Second_Step_AI
End If
Call UpdateJVEntries
'Call Demo1bb8
Application.StatusBar = "Processing row " & i & " of " & lchkw & " - Running Time: " & Format(Now - timetaken, "hh:mm:ss")
Wk.UsedRange.Clear
Wk.Range("A1:A" & lastCol).Value = WorksheetFunction.Transpose(Srk.Range("A1", ColumnLetter & lastCol))
Next i
lastRow = ThisWorkbook.Sheets("JV").Cells(Rows.Count, 1).End(xlUp).Row ' Update last row after adding new rows
Dim xi As Long
Dim jvSheet As Worksheet
Set jvSheet = ThisWorkbook.Sheets("JV")
With jvSheet
lastRow = .Cells(.Rows.Count, "H").End(xlUp).Row
.Range("H1:H" & lastRow).AutoFilter Field:=1, Criteria1:=0
If Application.WorksheetFunction.Subtotal(103, .Columns("H:H")) > 1 Then
.Range("H2:H" & lastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
.AutoFilterMode = False
End With
Call Get_DR_CR_Total_AI
timetaken = Now() - timetaken
With Enty.Cells.Font
.Name = "Century Gothic"
.Size = 9
End With
ActiveWindow.DisplayGridlines = False
Trg.UsedRange.Clear
MsgBox "Completed JV Booking !!! " & vbNewLine & vbNewLine & " Entry Validation Value -" & Enty.Range("M4").Value & vbNewLine & vbNewLine & " Time Taken is - " & Format(timetaken, "HH:MM:SS"), vbInformation, "Hi " & Application.UserName
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.DisplayStatusBar = False
End Sub