Skip to content

Instantly share code, notes, and snippets.

@gtaing1
Created March 6, 2017 09:04
Show Gist options
  • Save gtaing1/734ebe4fd439061c11604774e4e04a7e to your computer and use it in GitHub Desktop.
Save gtaing1/734ebe4fd439061c11604774e4e04a7e to your computer and use it in GitHub Desktop.
Function GetFilenameFromPath(ByVal strPath As String) As String
If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
End If
End Function
Function isOpen(ByVal strPath As String)
Dim wBook As Workbook
On Error Resume Next
Set wBook = Workbooks(strPath)
If wBook Is Nothing Then 'Not open
Application.Workbooks.Open (strPath)
End If
End Function
Sub FileBrowser()
Dim strPath As String
Dim wb As Workbook
strPath = Application.GetOpenFilename(, , "Select your File")
If strPath = "" Then Exit Sub
isOpen (GetFilenameFromPath(strPath))
Set wb = Application.Workbooks(GetFilenameFromPath(strPath))
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
Range("D7").Select
ActiveCell.FormulaR1C1 = _
"=INDEX('[&strPath&]Campaign Spreadsheet'!C18,MATCH(RC[2],'[&strPath&]Campaign Spreadsheet'!C4,0))"
Range("D7").Select
Selection.AutoFill Destination:=Range("D7:D59"), Type:=xlFillDefault
Range("D7:D59").Select
ActiveWindow.LargeScroll Down:=-5
Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.ColumnWidth = 18.89
Range("E7").Select
ActiveCell.FormulaR1C1 = "=MID(RC[-1],FIND(""PF"",RC[-1],8),6)"
Range("E7").Select
Selection.AutoFill Destination:=Range("E7:E59"), Type:=xlFillDefault
Range("E7:E59").Select
ActiveWindow.LargeScroll Down:=-6
Range("E7").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveWindow.LargeScroll Down:=-2
Range("D7").Select
Range(Selection, Selection.End(xlToLeft)).Select
Range("D7:E7").Select
Application.CutCopyMode = False
Range("E7").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.End(xlUp).Select
Range("D7").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.LargeScroll Down:=0
Application.CutCopyMode = False
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Range("D12").Select
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment