I want to write a macro that will copy a selected range of cells from one Excel file to another. I tried that code but it doesn't work. The only action that I see is that wbk and wbk 1 workbooks are open, but the rest of code is not executed, so I can't copy what I need. Any ideas what is wrong?
Sub new()
Dim wbk As Workbook
Dim wbk1 As Workbook
Set wbk = Workbooks.Open("C:\Users\Marcin\Desktop\plik zrodkowy.xlsm")
Set wbk1 = Workbooks.Open("C:\Users\Marcin\Desktop\Zeszyt2.xlsm")
' now you can manipulate the data in the workbook anyway you want, e.g. '
Dim x, y As Variant
x = wbk.Worksheets("Sheet1").Range(Cells(1, 1), Cells(13, 2))
y = wbk1.Worksheets("Sheet1").Range(Cells(1, 20), Cells(13, 23))
Dim x, y As Variant
is not what you seem to think it is: variabley
is explicitly declared as Variant, but variablex
defaults to Variant since there is no declaration of the variable type for the variablex
. This is VBA and it's different than... If you would do the followingDim x, y As Double
theny
is "Double" type andx
is still a Variant :-) Correct way isDim x As Variant, y As Variant
- Gene