I wrote a macro, which I would like to use in different excel files, which have almost the same table structure but different data.
So is it possible anyhow just to \"in
The simplest, best way to do this is to create a "commander" XLSM which contains the macro but none of the data. All it does is open the specified Excel files and run the macro on them. You can either type/paste in the name of a specific file(s), you can loop through an entire directory, etc. It is very easy to run a macro on a different workbook than the one which actually contains the macro. Something like this below... piece of cake.
Sub MultipleFileMacro()
Dim wb As Excel.Workbook
Dim fso As Scripting.FileSystemObject
Dim f As Scripting.File
Set fso = New Scripting.FileSystemObject
For Each f In fso.GetFolder("c:\samplefolder").Files
Set wb = Excel.Workbooks.Open(f)
MyMacro wb
wb.Close
Next f
End Sub
------------
Sub MyMacro(wb As Excel.Workbook)
'do something here
End Sub