I need ideas
example : i want to sum different work books but instead of writing a formula every time, i want a box that i can input the files and it will write the formula automatically
I need ideas
example : i want to sum different work books but instead of writing a formula every time, i want a box that i can input the files and it will write the formula automatically
It is possible.
Try something like the code below.
![]()
Sub AddFormula2SelectedWb() ' Macro : Excample for adding formale to selected files ' Authur : Gerard Veldstra ' ' Date : 27 jan 2014 ' For : ExcelForum.com ' Dim sSDrive As String Dim sPath As String Dim sFName As String Dim iCount As Integer Dim fd As FileDialog Dim vrtSelectedItem As Variant Dim wb As Workbook ' Save the current directory. sSDrive = CurDir ' Set the path to the folder that you want to open. sPath = "H:\001ExcelForum\2014\jan\Multi books" ' Change drive/directory to sPath. ChDrive sPath ChDir sPath Set fd = Application.FileDialog(msoFileDialogFilePicker) With fd .AllowMultiSelect = True .Title = "Choose workbook for formula adding" .InitialFileName = sPath .InitialView = msoFileDialogViewList 'show Excel workbooks and macro workbooks .Filters.Clear .Filters.Add "Excel workbooks", "*.xlsx*" .Filters.Add "Excel macros", "*.xlsm" .Filters.Add "Excel 97-2003 Files", "*.xls" .FilterIndex = 2 .ButtonName = "Ad formula" If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. iCount = 0 Application.ScreenUpdating = False Application.EnableEvents = False For Each vrtSelectedItem In .SelectedItems sFName = Right(vrtSelectedItem, Len(vrtSelectedItem) - InStrRev(vrtSelectedItem, Application.PathSeparator, , 1)) On Error Resume Next Set wb = Workbooks.Open(vrtSelectedItem) On Error GoTo 0 If Not wb Is Nothing Then ' Add the formula to sheet Workbooks(sFName).Sheets(1).Range("A1").Formula = "=5+6" 'Change formula to desire wb.Close SaveChanges:=True End If Next Application.ScreenUpdating = True Application.EnableEvents = True End If End With Set fd = Nothing ChDrive sSDrive ChDir sSDrive End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks