PDA

Click to See Complete Forum and Search --> : VB for EXCEL


Norah
Sep 10th, 2004, 11:52 AM
I use VB for Excel with no problems except these two:

1. I need to copy in a given Excel file a sheet named, say "one", into a sheet named, say "two".Suppose the sheet "one"has columns A and B. I use the following code:

Do while n>=1 and sheet.application. worksheets("one").range("A"&n)<>""
sheet.application.worksheets("two").range(A&n).value=sheet.application.worksheets("one").range("A"&n)
sheet.application.worksheets("two").range(B&n).value=sheet.application.worksheets("one").range("B"&n)
n=n+1
loop

This some times works and some times doesn't. Is there a better way?

2. As the running of my codes takes quite a lot of time, it would be convenient for me to pause at some time and resume later on.
How can I do this?

RobDog888
Sep 10th, 2004, 01:10 PM
Here. This takes less than one second. It copies the sheet "One"
into the same workbook and renames the copy to Two. As long
as you wanted the entire sheet copied this is the way to go.

Edit: Forgot to post the code!
Public Function CopySheet()
Worksheets("One").Copy Worksheets("Sheet2")
Worksheets("One (2)").Name = "Two"
End FunctionVB/Outlook Guru!