Cnage VBA code to select filename

ezonemy

New Member
Joined
Dec 7, 2014
Messages
19
I have the below VBA code running. However the filename SCORESHEET always changes as my staff’s are required to save the worksheet once they opened it. The macro in this sheet is activated via command button. They will save the filename something like this STAFF NAME-KPI-DDMMYY (e.g. JOHN-KPI-181214). The sheetname would not change. Please advice on how to make the changes in the VBA code below to adopt the changes in filename.</SPAN>

Code:
Sub CopyData() 
    Application.ScreenUpdating = False 
    Dim foundDate As Range 
    Dim wb As Workbook 
    Set wb = Workbooks.Open("C:\Users\Mario\Desktop\Forum Help\MASTER.xlsx") 
    Dim ws As Worksheet 
    For Each ws In Workbooks("MASTER.xlsx").Sheets 
        If ws.Name = Workbooks("Scoresheet.xlsm").Sheets("Sheet1").Range("B2").Value Then 
            Set foundDate = ws.Range("A:A").Find(Workbooks("Scoresheet.xlsm").Sheets("Sheet1").Range("E2"), LookIn:=xlValues, lookat:=xlWhole) 
            If Not foundDate Is Nothing Then 
                foundDate.Offset(0, 1) = Workbooks("Scoresheet.xlsm").Sheets("Sheet1").Range("H2") 
            End If 
        End If 
    Next ws 
    wb.Close True 
    Application.ScreenUpdating = True 
End Sub

And also please advice code to autosave the sheet at end of the code above.

Thank you a lot all for your time.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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