Macro/VBA help - lots of xls imports

  • Thread starter Thread starter Steve M
  • Start date Start date
S

Steve M

I have 3 spreadsheets A, B and C

A & B contain information in the exact same format

With C I have 2 columns that compare their values against each other
and highlight any differences(through a small VBA script)

I want 2 buttons in C spreadsheet that:

Button 1: Offers the user to open a spreadsheet(A - name can vary) then
copies A2:A500 of that spreadsheet to spreadsheet C(A2:A500)

Button 2: Offers the user to open a spreadsheet(B - name can vary) then
copies B2:B500 of that spreadsheet to spreadsheet C(B2:B500)

Any ideas if this is possible
 
Sub GetfromA()
Dim fName as Variant
Dim bk as Workbook, sh as Worksheet
set sh = Activesheet
fname = Application.GetOpenfilename("Excel Files (*.xls),*.xls")
if fName = False then exit sub
set bk = Workbooks.Open(fName)
bk.Worksheets(1).Range("A2:A500").copy _
Destination:=sh.Range("A2")
bk.close SaveChanges:=False
End Sub


Sub GetfromB()
Dim fName as Variant
Dim bk as Workbook, sh as Worksheet
set sh = Activesheet
fname = Application.GetOpenfilename("Excel Files (*.xls),*.xls")
if fName = False then exit sub
set bk = Workbooks.Open(fName)
bk.Worksheets(1).Range("B2:B500").copy _
Destination:=sh.Range("B2")
bk.close SaveChanges:=False
End Sub
 
I will point you in the right direction as I am just off to a meeting.

use tools record macro and then carry out the open and copy stop th
macro and have a look at the code. Expect to replace the "selection
object with a range object which you will need to declare eg DI
myRange as range.

put a button on the the spreadsheet use a normal drawing object. righ
click on it and assign macro.

I might catch up later to see how you got on

regard
 
Back
Top