Modify and specify two open files

elmnas

Board Regular
Joined
Feb 20, 2015
Messages
206
Hello Excel people,

I have made following code the code is very simple,
the script copying certain columns from one place to another file.

I open the SourceFile.xls and import my.bas file to.

when you run the script you get a windowdialog you can selecta folder the script open the file (anything)_TSP.xls

it always copyingdata from the TargetFile.xls and paste into the Sourcefile.
I have now hardcoded the filenames but could someone help me to change it?
cause I always import the my.bas to the sourcefile so that is the sourcefile.


See code below

Code:
Sub VMergeColumns()


Dim myPath As String
Dim StrCurrentfile As String
Dim StrFName As String
Dim myLangFile As String
Dim intResult As Integer




Application.DisplayAlerts = True


intResult = Application.FileDialog(msoFileDialogFolderPicker).Show
    If intResult = 0 Then
        MsgBox "User pressed cancel macro will stop!"
    Exit Sub
    
        Else
        
        MyOrGPathFile = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"
        
     End If


StrCurrentfile = Dir(MyOrGPathFile & "*_TSP.xls")
Do While StrCurrentfile <> ""


myfile = MyOrGPathFile & StrCurrentfile


'MsgBox myfile
Set myTFile = Workbooks.Open(MyOrGPathFile & StrCurrentfile)


Columns(1).Select
Selection.Copy


Workbooks("SourceFile.xls").Activate
Columns("A:A").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "TT Number"
ActiveCell.Interior.ColorIndex = xlNone


Workbooks("TargetFile_TSP.xls").Activate
Columns("D:D").Select
Selection.Copy


Workbooks("SourceFile.xls").Activate
Columns("I:I").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "Source language"
ActiveCell.Interior.ColorIndex = xlNone


Workbooks("TargetFile_TSP.xls").Activate
Columns("E:E").Select
Selection.Copy


Workbooks("SourceFile.xls").Activate
Columns("J:J").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "Target Language"
ActiveCell.Interior.ColorIndex = xlNone


Workbooks("TargetFile_TSP.xls").Activate
Columns("G:G").Select
Selection.Copy


Workbooks("SourceFile.xls").Activate
Columns("K:K").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "No of New words"
ActiveCell.Interior.ColorIndex = xlNone


Workbooks("TargetFile_TSP.xls").Activate
Columns("H:H").Select
Selection.Copy


Workbooks("SourceFile.xls").Activate
Columns("L:L").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "No of Fuzzy matches"
ActiveCell.Interior.ColorIndex = xlNone


Workbooks("TargetFile_TSP.xls").Activate
Columns("I:I").Select
Selection.Copy


Workbooks("SourceFile.xls").Activate
Columns("M:M").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "No of 100% match And Repetitions"
ActiveCell.Interior.ColorIndex = xlNone


Workbooks("TargetFile_TSP.xls").Activate
Columns("L:L").Select
Selection.Copy


Workbooks("SourceFile.xls").Activate
Columns("V:V").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "No of 100% match And Repetitions"
ActiveCell.Interior.ColorIndex = xlNone




'Set noLangFilen = Workbooks.Open(MyOrGPathFile & MyFile)
'Application.DisplayAlerts = False
'noLangFilen.CheckCompatibility = False
'noLangFilen.Close SaveChanges:=True
StrCurrentfile = Dir


Loop




End Sub

Thank you in advance
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi,

I can see what your macro is doing but could you provide more details about what you want to change, please?

Do you want the macro to do something different, or to be more flexible or just to be run in a different way?

Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,860
Members
449,194
Latest member
HellScout

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