VBA Code:
Sub macGL_Detail_ImportAndFormat()
'
' macGL_Detail_ImportAndFormat() Macro
'
Dim fileLocation As String
Dim fileToOpen As Workbook
Application.ScreenUpdating = False
fileLocation = "\\company.corp\files\KDrive\DM Monthly Close\2024\04 2024\GL Detail\04 DVH Detail.xlsx"
'I would love to be able to loop or for/while or if/else, something ^^^ ^^^
' to get the file location open without me having to update the vba script each month
Workbooks.Open fileLocation
Windows("04 DVH Detail.xlsx").Activate
Sheets("GL Data").Select
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Windows("GL Detail Tieout v11").Activate
Sheets("DVH Detail Stage").Visible = True
Sheets("DVH Detail Stage").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("A:C").Select
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Columns("N:Y").Select
Selection.Delete Shift:=xlToLeft
Columns("O:O").Select
Selection.Delete Shift:=xlToLeft
Columns("P:T").Select
Selection.Delete Shift:=xlToLeft
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("GL Detail").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Sheets("DVH Detail Stage").Select
Range("A1").Activate
Selection.CurrentRegion.Select
Selection.ClearContents
Range("A1").Select
Windows("04 DVH Detail.xlsx").Activate
ActiveWorkbook.Close
Windows("GL Detail Tieout v11").Activate
ActiveWorkbook.RefreshAll
Sheets("DVH Detail Stage").Visible = False
Sheets("DVH Detail Import").Select
Range("C1").Select
Selection.FormulaR1C1 = "=NOW()"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Range("A1").Select
Sheets("DVH Detail Row-Count Log").Select
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select
Selection.FormulaR1C1 = "=TODAY()"
Sheets("DVH Detail Import").Select
Range("Import_ReportVersion").Select
Selection.Copy
Sheets("DVH Detail Row-Count Log").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("DVH Detail Import").Select
Range("Import_Rows").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("DVH Detail Row-Count Log").Select
Range("C2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A2:C2").Select
Application.CutCopyMode = False
Selection.Copy
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("DVH Detail Import").Select
Range("A1").Select
Application.CutCopyMode = False
Selection.FormulaR1C1 = ""
Range("A1").Select
ImportComplete = MsgBox("Import Complete", , "GL Detail Data Import")
End Sub
I'm fairly new to writing VBA and I don't have a lot of experience writing any coding language other than SQL and I'm not even very well versed in that. That's all, I just want to know how you'd go about cleaning this code up and reducing the redundancies (if there even are any)