Ask Question Forum:
C
O
M
P
U
T
E
R
2
8
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Y-position of the mouse cursor
Attachment:===
Open a file and select back the orginal sheet in VBA

and do a copy and paste that is fine for the following code. But when I want to do some paste the copy to offset positon into
the orginal workbook and sheets , it will create
run-time error when I use range(cells(8+a,8), cells(200, 11) instead of range("H8:K200")with a=0 . I create a variabel is want to
do offset paste, for example, a= 10 or 20....It seems when you open other excel file, the VBA could not select back the
orginal worksheet or workbookif using cells() syntax in range. How Can I select file or sheet between orginal one or opening one file or sheet ?
No error:
Workbooks("orginalworkbook").Sheets("orginal-sheet").Range("H8:K200").PasteSpecial xlPasteValues
Have RUn-time error:But Range("H8:K200")=Range(cells(8+a,8,),cells(200,11) if a=0, Right ?
Workbooks("orginalworkbook").Sheets("orginal-sheet").Range(cells(8+a,8,),cells(200,11)).PasteSpecial xlPasteValue
Please advise
Duncan
==================================
Sub Main() 'In orginal workbook and sheet
Dim wkdir as string
Dim datafilename as string
Dim sheetname as string
Dim a as string
a=0
wkdir = "d:"
datafilename="myexample"
sheetname="mysheet"
Workbooks.Open Filename:=wkdir & datafilename, ReadOnly:=True
Workbooks(datafilename).Sheets(sheetname).Range("A8:D200)").Select
Selection.copy
Workbooks("orginalworkbook").Sheets("orginal-sheet").Range("H8:K200").PasteSpecial xlPasteValues
'Workbooks("orginalworkbook").Sheets("orginal-sheet").Range(cells(8+a,8,),cells(200,11)).PasteSpecial xlPasteValues and
'runtime error if it is used
ActiveWorkbook.Close False
End sub
I already did if you look at my code.
Range("h8:k200")=range(cells(8+a,8),cells(200,11)) if a=0 right?
Why using cells() is not passed but range("h8:k200") is passed ?
I already did if you look at my code.
Range("h8:k200")=range(cells(8+a,8),cells(200,11)) if a=0 right?
Why using cells() is not passed but range("h8:k200") is passed ?
I already did if you look at my code.
Range("h8:k200")=range(cells(8+a,8),cells(200,11)) if a=0 right?
Why using cells() is not passed but range("h8:k200") is passed ?
I already did if you look at my code.
Range("h8:k200")=range(cells(8+a,8),cells(200,11)) if a=0 right?
Why using cells() is not passed but range("h8:k200") is passed ?
I already did if you look at my code.
Range("h8:k200")=range(cells(8+a,8),cells(200,11)) if a=0 right?
Why using cells() is not passed but range("h8:k200") is passed ?