PDA

View Full Version : Cut & Paste Error, Excel Hang?



AmazingTrans
04-26-2007, 02:25 PM
Hello Gurus,
I have been reading thread from this forum and everybody have a very wide knowledge of solving problems. So, I am giving a try...

Currently, I am collecting datas from a device and it is saved in the excel. In Sheet1, A1; the values changes from 1 to 0 to 1. and the values are in range of A5 to B10. When, the cell A1 changes to 1, the macro will cut and paste A5:B10 to Sheet2 and if it is zero do nothing. The macro will loop untill midnight and an email will be sent out. I will be writing this line of code later.
I ran the code and I am having this error: PasteSpecial of method range class failed. and if it works, i think the excel will hang too. Any ideas?

y = 1
Do While Sheet1.Cells(1, 1).Value = 1
Sheet1.Range("A5:B10").Cut
Sheet2.Cells(y, 1).PasteSpecial (xlPasteValues)
y = y + 9
Loop
End Sub

Thanks.

mdmackillop
04-26-2007, 03:19 PM
Excel will not let you Cut and PasteSpecial so try the following
Sheet1.Range("A5:B10").Copy
Sheet2.Cells(y, 1).PasteSpecial xlPasteValues
Sheet1.Range("A5:B10").ClearContents
I don't see the point of the loop, as A5:B10 will be clear after the first execution