New to VBA and need help with a macro

Kahlan1177

New Member
Joined
Oct 4, 2018
Messages
6
Hi,
So i am working on a macro that will allow me to open a window in workbook 1 to find an excel report file and then format that report. Once the format is complete it then copies and pastes to workbook 1 to the specified tab so that the original file is not touched or modified. I have 3 reports to do in this fashion.

This is what i have so far, but it keeps bugging when it goes to format, i only attached the main routine and one of the sub routines. Can anyone help me see my mistake?


Code:
Public Sub RiskOpen_Workbook_FileDialog()
'
' RiskOpen_Workbook_FileDialog Marco
' open file window to choose file
'
 
'
Dim fd As FileDialog
Dim lngPathLen As Long
Dim strPath As String, strfile As String, strTemp As String
strTemp = ""
Dim strfilepath as String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
    .AllowMultiSelect = False
    .ButtonName = "Select"
    .InitialView = msoFileDialogViewDetails
    .Title = "Select File To Update"
   
    .InitialFileName = "\\Reports\Privacy & Reputational Risk Audit"
        With .Filters
  
        .Clear
        .Add "Excel Workbooks", "*.xls; *.xlsx"
     
    End With
   
    .FilterIndex = 1
   
    If .Show = -1 Then
        strTemp = .SelectedItems(1)
    End If
   
    Set fd = Nothing
  
End With
 
If strTemp <> "" Then
 
    lngPathLen = InStrRev(strTemp, "")
 
    strPath = Left(strTemp, lngPathLen)
    strfile = Right(strTemp, Len(strTemp) - lngPathLen)
   
    Debug.Print strPath
    strfilepath = strPath & strfile
   
    If Left(strfile, 6) = "MonAdj" Then
        Call MonAdj
    End If
   
     If Left(strfile, 5) = "Award" Then
        Call Award
    End If
   
    If Left(strfile, 5) = "Other" Then
        Call Other
    End If
   
End If
 
End Sub
 
 
 
 
 
 
 
Public strfilepath As String
 
Sub MonAdj()
'
' MonAdj Macro
 
'
    Workbooks.Open Filename:=strfilepath
    Application.Width = 1011
    Application.Height = 757.5
    Cells.Select
    Cells.EntireColumn.AutoFit
    Selection.ColumnWidth = 8.13
    Rows("1:4").Select
    Selection.Delete Shift:=xlUp
    ActiveWindow.SmallScroll Down:=-18
    Columns("B:B").ColumnWidth = 8
    Columns("B:B").EntireColumn.AutoFit
    Columns("C:C").EntireColumn.AutoFit
    Columns("B:B").Select
    Selection.Delete Shift:=xlToLeft
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("H:H").Select
    Selection.Delete Shift:=xlToLeft
   Selection.Delete Shift:=xlToLeft
    Selection.Delete Shift:=xlToLeft
    Columns("G:G").EntireColumn.AutoFit
    Cells.Select
    Selection.Copy
    Windows("MACRO Sampler .xlsm").Activate
    Sheets("Mon Adj").Select
    Cells.Select
    ActiveSheet.Paste
End Sub
 
Last edited by a moderator:
That's fine, but you should only have one declaration for the variable.
If you delete all but one of lines, does your code work?

Morning Fluff!
Thank you so much! I removed the declaration from my other module and the Dim at the begining and it works perfectly!
Thank you again for all your help!
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top