VBA code goes wrong!~~

abnankash

New Member
Joined
Feb 6, 2011
Messages
8
strfilename = "X:\ToPost\" & y & "\" & mth & "\ToPost " & Format(Date, "ddmmmyy") & " " & Hour(Now()) & Minute(Now())
h = Hour(Now())
m = Minute(Now())
Set appExcel = Excel.Application
If Dir(strfilename) <> "" Then
Set wbk = appExcel.Workbooks.Open(strfilename & ".xls")
Else
Set wbk = appExcel.Workbooks.Add
wbk.SaveAs strfilename & ".xls"
End If

i = 1
Do While SpreadSht.Worksheets(1).Range("A" & i) <> ""
i = i + 1
Loop
SpreadSht.Worksheets(1).Range("A1:Q" & i - 1).Copy
wbk.Range("A1:Q" & i - 1).Paste
wbk.Save
wbk.Close


I got a popup msg when the programme goes to third last row.
eg: wbk.Range("A1:Q" & i - 1).Paste

It says that Object does not support this method. How can I solve it?
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try

Code:
SpreadSht.Worksheets(1).Range("A1:Q" & i - 1).Copy Destination:=wbk.Range("A1")
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

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