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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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