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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA programming in Excell

Status
Not open for further replies.

Evening

Technical User
Jan 19, 2005
45
0
0
CA
I have a workbook with 5 worksheets.
I made some VBA prgram initiating in worksheet-1.
Is it possible with this same VBA program to choose other worksheets,(worksheet-2) copy some cells from worksheet 2 and also paste them in the same worksheet-2.
This will be repeated with worksheet 3,4 5, and in the end to come back to worksheet-1.
I tried to get VBA codes recording macro, but when i put everything in my VBA program, doesn't work. As soon as jumps from worksheet 1 to worksheet 2, it stops.
 
in my VBA program
Which code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Please post your code and any error messages you are getting.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"What version of URGENT!!! are you using?
 
Here is the part of the code:

I am in worksheet BAS_E. from this worksheet I want to go
to worksheet GEA_E


Sheets("GEA_E").Select
Range("D10:D13").Select
Application.CutCopyMode = False
Selection.Copy
Range("H10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("BAS_E").Select


When the program goes to worksheet GEA_E, the error comes up: Run Time error 1004 Sele Method of Range class failed.
When I try to de-bug, i see the program has stopped at line
Range("D10:D13").Select

 
Not sure how advanced you are, but the basic code is:

Code:
Sheets("GEA_E").Select
ActiveSheet.Range("D10:D13").Select
Selection.Copy
ActiveSheet.Range("H10:H13").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

When you want to do new sheets, you would modify the first line and enter the different sheet name.

If it is the same cells on each, I would recommend doing a loop instead of copying this code four or five times and typing in different sheet names. For example:
Code:
Dim wksheet As Worksheet

For Each wksheet In Worksheets
    wksheet.Select
    ActiveSheet.Range("D10:D13").Select
    Selection.Copy
    ActiveSheet.Range("H10:H13").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Next wksheet
Is one way to go through each sheet and to copy those same cells on each sheet for the entire workbook, without having to type in the worksheet names or change your code from the copy/paste method.

[blue]When birds fly in the correct formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness.[/blue]
 
Thanks Pinkgecko, it's working.
I'm not a profesional programmer, i just used a macro creating the program, where the macro created the
program as i described. Later when i put the macro codes in my full VBA program, just didnt work. Now I understand why....
Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top