1
votes

I like to compare two workbooks with different sheet, How can I set as an object for workbook1-->Sheet1 , workbook2--->(sheet1)

I can able to compare the worksheet inside the same workbook, Butwhere as if I want to select the sheet the "getopenfilename". how can i assign the name as an object.

code:

Dim tabWb As Workbook            'Workbook2
Dim tabWS As Worksheet           'analysing worksheet
Filename = Application.GetOpenFilename("Excel files (*.xls*),*.xl*", Title:="Open data")
Set wb = ActiveWorkbook
Set tabWS = Sheets("Tabelle1")


Dim bsmWS As Worksheet      ' workbook1
Set bsmWS = Sheets("Sheet1") ' currentworksheet

Workbook1(sheet1) is my current workbook and work sheet, I like to get some data from the another workbook2(sheet1). How can i make an object for the both worksheets.I am getting compileing failure in "set bsmws"

1

1 Answers

2
votes
Sub test()

    Dim strFileName as String
    Dim wbTarget As Workbook
    Dim wbSource As Workbook
    Dim wsTarget As Worksheet
    Dim wsSource As Worksheet

    strFileName = Application.GetOpenFilename("Excel files (*.xls*),*.xl*", Title:="Open data")

    Set wbSource = ThisWorkbook
    Set wbTarget = Workbooks.Open(strFileName)

    Set wsSource = wbSource.Worksheets("Sheet1")
    Set wsTarget = wbTarget.Worksheets("Sheet1")

    'to copy from Target - > Source

    wsTarget.Range("B2").Resize(5, 5).Copy wsSource.Range("B2")

    'etc.

End Sub