|
-
Sep 8th, 2005, 05:29 PM
#1
Thread Starter
New Member
[RESOLVED] programming macros in excel
I have 20 sheets with data, and I want save some data in another sheets, I have this code :
VB Code:
Windows("FICHAS SINANPE.xls").Activate
Sheets("001 Elbert Zavaleta Zavaleta").Select
Range("B6:B14").Select
Selection.Copy
Windows("Dbase personal.xls").Activate
Sheets("Datos Personales").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
Windows("FICHAS SINANPE.xls").Activate
Sheets("002 Dante Alemán De Lama").Select
Range("B6:B14").Select
Selection.Copy
Windows("Dbase personal.xls").Activate
Sheets("Datos Personales").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
This code run, but I have 20 sheets and I want to do a bucle where the sheets are inside the bucle, but I don't know how to do
-
Sep 8th, 2005, 05:48 PM
#2
Re: programming macros in excel
Hi darwingomez, welcome to VBForums! 
I'm a bit confused, what do you mean by bucle?
Do you mean that you want to paste the same data into multiple sheets?
-
Sep 8th, 2005, 05:55 PM
#3
Thread Starter
New Member
Re: programming macros in excel
when I say bucle, I want to say (for i = 0 to i <20), but I don't know how to do write the code exactly to can do the same for the 20 sheets
-
Sep 8th, 2005, 06:05 PM
#4
Re: programming macros in excel
Assuming that those are the first 20 sheets in the Workbook, this code should do the trick:
VB Code:
Dim i as Integer
With Workbooks("FICHAS SINANPE.xls")
For i = 1 to 20
.Activate
.Sheets(i).Select
Range("B6:B14").Select
Selection.Copy
Windows("Dbase personal.xls").Activate
Sheets("Datos Personales").Select
Range("A" & (i+1)).Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
Next i
End With
-
Sep 8th, 2005, 06:36 PM
#5
Thread Starter
New Member
Re: programming macros in excel
-
Sep 8th, 2005, 07:22 PM
#6
Re: programming macros in excel
I know it may be solved but as another option you can use the .Copy method for the sheets collection to do a Copy/Paste all in one line without doing any Selection or Activate. Should be faster still. 
VB Code:
Workbooks("FICHAS SINANPE.xls").Sheets(i).Copy After:=Workbooks("Datos Personales").Sheets(Sheets.Count)
This will copy each sheet in the FICHAS SINANPE.xls workbook and paste them into the Datos Personales workbook. Now if you dont want to copy the entire sheet then your current method is better.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 9th, 2005, 06:38 AM
#7
Re: programming macros in excel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|