Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Copy Paste Question

Status
Not open for further replies.

baycolor

MIS
Mar 23, 2005
148
US
Hi, I'm really new to Excel VBA programming and have the question below. I'm using Excel 2003 on a laptop.

I have the following procedure that is passed an array of worksheet names:

Sub EmptyWorksheets(IndWrkShtArr As Variant)
For i = 1 To UBound(IndWrkShtArr)
Sheets(i).Select
Cells.Select
Selection.ClearContents
Range("A1").Select
RawData.Range("A:A").Copy Destination:=Sheets(i).Range("A1")
Next i
End Sub

Seventh line is all on one line in the Excel editor window with the end looking like...
:=RawData.Range("A2:A3")

RawData is a tab in my workbook.

Each time the code works on a sheet it selects all cells, clears them puts the focus on cell A1 and then attempts to copy the firs row of header data from my raw data tab to the active sheet. The mesage I get is:

Run-time error '424':
Object required

When I click debug the editor highlights line seven of the procedure.

I copied this copy/paste example from a site that said it is more efficient then copy paste via the clipboard (something like):
RawData.Range("A:A").Copy
Sheets(i).Range("A1").paste

I've attempted to change Sheets(i) to IndWrkShtArr(i)

Also attempted to copy and paste into the same worksheet with
RawData.Range("A:A").Copy Destination:=RawData.Range("A2")

I'm not all that familiar with the Excel/Office VBA object model and I don't have time to learn it all right now. Any help is appreciated.

Thanks
 



Please post VBA, code, macro questions in Forum707.

Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
OK not sure what gives I posted them in the VBA forum and they don't show up. I'm wondering if something on the site is preventing a duplicate post
 



Try it again. Use a different title. Go slow and be sure you crossed your i's and ditted your t's.


Skip,
[sub]
[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top