Hi All,
I am looking for help in changing a vlookup I am doing in the macro below. In step 5 I am looking at a 4 digit numeric code in Column E of the main worksheet(Ceridian) and dropping to a single worksheet (Department List) to lookup the number (in Column A) and copy the corresponding name (from Column B) back to the appropriate column (K) on the main worksheet. The info has all been from a department list worksheet.
I now need to look at the individual 2 letter code (In column D) to determine which of 3 department lists the lookup has to be conducted in. There is duplication of the 4 digit department numbers with different department names as a result. I also need it to go down the entire column and just go to the appropriate list for each row with a 2 letter code in D. The codes are CC for the "Dept List TCO" sheet, PA-TZ for the "Dept List Parish" sheet and SA-SW for the "Dept List School" Sheet. There is no longer a Department List sheet. Any suggestions on where to go from here would be greatly appreciated. Everything I have tried so far does just one condition (Parish) and leaves the others the same.
Thanks,
Barry
I am looking for help in changing a vlookup I am doing in the macro below. In step 5 I am looking at a 4 digit numeric code in Column E of the main worksheet(Ceridian) and dropping to a single worksheet (Department List) to lookup the number (in Column A) and copy the corresponding name (from Column B) back to the appropriate column (K) on the main worksheet. The info has all been from a department list worksheet.
I now need to look at the individual 2 letter code (In column D) to determine which of 3 department lists the lookup has to be conducted in. There is duplication of the 4 digit department numbers with different department names as a result. I also need it to go down the entire column and just go to the appropriate list for each row with a 2 letter code in D. The codes are CC for the "Dept List TCO" sheet, PA-TZ for the "Dept List Parish" sheet and SA-SW for the "Dept List School" Sheet. There is no longer a Department List sheet. Any suggestions on where to go from here would be greatly appreciated. Everything I have tried so far does just one condition (Parish) and leaves the others the same.
Thanks,
Barry
Option Explicit
Sub NamedRange()
'Create a named range for Step_5
Dim Rng1 As Range
Set Rng1 = Sheets("Department List").Range("A1:B613")
ActiveWorkbook.Names.Add Name:="Dept", RefersTo:=Rng1
End Sub
Sub AllSteps()
'Includes step 1 to 10
Dim x As String
Dim lr As Long
Dim i As Integer
Dim intRowCount As Integer
Dim ws As Worksheet
Dim fc As Worksheet
Dim r As Long
Dim lastRow As Long
Dim Dept As Range
Dim hds As Worksheet
'Set ls = Worksheets("Department List")
Set Dept = Sheets("Department List").Range("A1:B613")
Application.StatusBar = "This macro may take a few minutes to run.... please wait"
Application.ScreenUpdating = False
lr = Range("A" & Rows.Count).End(xlUp).Row
'Delete columns with commas in Step_1
Range("B1,D1,H1,J1").EntireColumn.Delete
'replace blanks with zeros Step_2
Range("F1:F" & lr).Select
Selection.Replace What:="", Replacement:="0", LookAt:=xlWhole
Range("F1").Select
Columns("F:F").Select
Selection.NumberFormat = "#,##0.00"
'Replace all (235910,235920,237000,238000)account numbers with '219030,219035,219050,219070'
Range("C1:C" & lr).Select
Selection.Replace What:="235910", Replacement:="219030", LookAt:=xlWhole
Selection.Replace What:="235920", Replacement:="219035", LookAt:=xlWhole
Selection.Replace What:="237000", Replacement:="219060", LookAt:=xlWhole
Selection.Replace What:="238000", Replacement:="219070", LookAt:=xlWhole
'Step_3, Step_4,
'Step_7, Step_8, Step_9 & Step_10 are combined within the 'Range("L" & i).Value = Range("D" & i).Value & etc... line
'Create_Balance_Sheet_Dept_01_0000_Step_3 & CopyDeptNames_ColumnJ_Step_4
'Formulas didnt trigger when tested, changed to vba
intRowCount = Range("A1").CurrentRegion.Rows.Count
For i = 1 To intRowCount
Select Case Range("C" & i).Value
Case 100000 To 299999
Range("I" & i).Value = "01-Oper:0000 Balance Sheet"
Range("J" & i).Value = "01-Oper:0000 Balance Sheet"
Range("L" & i).Value = Range("D" & i).Value & " " & Range("B" & i).Value
Range("M" & i).Value = Range("D" & i).Value & " " & Range("G" & i).Value & " " & Range("B" & i).Value
Case Else
Range("I" & i).Value = Range("E" & i).Value 'Changed from C to E
Range("J" & i).Value = Range("E" & i).Value 'Changed from C to E
Range("L" & i).Value = Range("D" & i).Value & " " & Range("B" & i).Value
Range("M" & i).Value = Range("D" & i).Value & " " & Range("G" & i).Value & " " & Range("B" & i).Value
End Select
Next i
'Format Column J Step_4
Columns("J:J").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'Create named range (Code at top of this module)
NamedRange
'Create VlookUp and hardcode values Step_5 & Step_6
With Sheets("Ceridian File")
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
With .Range("K1:K" & lastRow)
.Formula = "=VLOOKUP(J1,Dept,2,0)"
.Value = .Value
End With
End With
'Replace all (not found in list - #N/A) errors with 'Not Found'
Range("K1:K" & lr).Select
Selection.Replace What:="#N/A", Replacement:="Not Found", LookAt:=xlWhole
'Copy_Entity_Names_to__IIF_Conversion_Sheet_Col_B_Step_12
Range("D1:D" & lr).Copy Destination:=Sheets("IIF Conversion").Range("B1")
Range("B1:B" & lr).Copy Destination:=Sheets("IIF Conversion").Range("D1")
Range("C1:C" & lr).Copy Destination:=Sheets("IIF Conversion").Range("E1")
Range("K1:K" & lr).Copy Destination:=Sheets("IIF Conversion").Range("F1") 'Changed from I to K
Range("F1:F" & lr).Copy Destination:=Sheets("IIF Conversion").Range("G1")
Range("M1:M" & lr).Copy Destination:=Sheets("IIF Conversion").Range("I1")
'CreateIFFSpecialColumns_SPL_and_GENERAL_JOURNAL Step_13
With Sheets("IIF Conversion")
lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
With .Range("A1:A" & lastRow)
.Formula = "=IF(ISBLANK(A1),"""",""SPL"")"
.Value = .Value
End With
End With
With Sheets("IIF Conversion")
lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
With .Range("C1:C" & lastRow)
.Formula = "=IF(A1=""SPL"",""GENERAL JOURNAL"","""")"
.Value = .Value
End With
End With
'Call sort macro, need to look at this
'Call IIF_Final_Presort_Step_14
'IIF_Final_Format_Prior_To_Sort Macro Step_15
Sheets("IIF Conversion").Select
Range("A1").Select
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Set hds = ThisWorkbook.Sheets("Headers")
Set fc = ThisWorkbook.Sheets("IIF Conversion")
hds.Range("A1:I3").Copy fc.Range("A1")
'IIF_Conversion_Sheet_Data_Sort_Old_Procedure_Step_16A, no changes
Call IIF_Conversion_Sheet_Data_Sort_Old_Procedure_Step_16A
'Format all new ws
Call FormatWS_rs2k
'Resize columns to fit data
Columns("A:M").EntireColumn.Autofit
' Range("A1:J" & lr).Copy Destination:=Sheets("Working Sheet").Range("A1")
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
Sub FormatWS_rs2k()
Dim lr As Long
Dim ws As Worksheet
Dim hds As Worksheet
Dim i As Integer
Dim intRowCount As Integer
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Sheets
If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" And ws.Name <> "Sheet14" _
And ws.Name <> "Ceridian File" And ws.Name <> "Working Sheet" _
And ws.Name <> "Department List" And ws.Name <> "IIF Conversion" _
And ws.Name <> "Headers" And ws.Name <> "CC1" And ws.Name <> "PB-PP" _
And ws.Name <> "PQ-PV" And ws.Name <> "PW-QJ" And ws.Name <> "QK-QT" _
And ws.Name <> "QU-RE" And ws.Name <> "RF-RT" And ws.Name <> "RU-SC" _
And ws.Name <> "SD-SK" And ws.Name <> "SM-SS" And ws.Name <> "ST-TF" And ws.Name <> "TH-TZ" Then
ws.Select
'Add 'TRNS' & 'ENDTRNS' to Col A
ws.Range("A4").Value = "TRNS" 'This adds 'TRNS' to A4
'#### This changes all of column A to 'TRNS' ####################
' intRowCount = Range("A4").CurrentRegion.Rows.Count + 3
' For i = 1 To intRowCount
' ActiveCell.Value = "TRNS"
' ActiveCell.Offset(1, 0).Select
' Next i
'################################################################
lr = Range("A" & Rows.Count).End(xlUp).Row
ws.Range("A" & lr).Offset(1, 0).Value = "ENDTRNS"
'Add headers to new sheets
Set hds = ThisWorkbook.Sheets("Headers")
hds.Range("A1:I3").Copy ws.Range("A1")
'Move lr var to Col G and Total Col G
'lr = Range("G" & Rows.Count).End(xlUp).Row
'ws.Range("G" & lr).Offset(3, 0).Formula = WorksheetFunction.Sum(Range(Range("G5"), Range("G5").End(xlDown)))
lr = Range("G65536").End(xlUp).Row + 3
Cells(lr, 7).Formula = "=SUM(G4:G" & lr - 1 & ")"
Calculate
'Format 'Total Cell'
'ws.Range("G" & lr).Offset(3, 0).Select
ws.Range("G" & lr).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ws.Range("A1").Select
End If
'Resize columns to fit data
ws.Range("A:I").EntireColumn.Autofit
Next ws
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic = True
End Sub