0% found this document useful (0 votes)
62 views2 pages

Practise

The document outlines a VBA script for creating an Excel file with five sheets, each collecting user input for names, countries, emails, phone numbers, and gender details. After populating the sheets, the script copies the data from these sheets into a single sheet of another Excel file. Finally, it closes all workbooks and cleans up the Excel application objects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views2 pages

Practise

The document outlines a VBA script for creating an Excel file with five sheets, each collecting user input for names, countries, emails, phone numbers, and gender details. After populating the sheets, the script copies the data from these sheets into a single sheet of another Excel file. Finally, it closes all workbooks and cleans up the Excel application objects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

'creating an excel file and entering the data in 5 sheets of file and copying all

the data to another file within single sheet

Sub Excelfile
Dim objfso,objexc,i As String,j As String,K As String, L As Int, M As String,
objexcel1
Set objfso = creatingobject("Scripting.Filesystemobject")
Set objexc = Createobject("Excel.Application")
objexc.workbooks.add
objexc.Activeworkbook.SaveAs("C:\New folder\Example.xlsx")
objexc.workbooks.open(""C:\New folder\Example.xlsx")
objexc.worksheet.add after:=worksheet(3) , count =2
objexc.worksheets(1).Name = "Employeename".cells(1,1)= "Names"
for i=2 To 10 Step = 1
cells(i,1)=Inputbox("Enter the names")
Next
objexc.Activeworkbook.Save

objexc.worksheets(2).Name = "Country".cells(1,1)= "Countryname"


for j=2 To 10 Step = 1
cells(j,1)=Inputbox("Enter the name of the country")
Next
objexc.Activeworkbook.Save

objexc.worksheets(3).Name = "Email".cells(1,1)= "E-id"


for K=2 To 10 Step = 1
cells(K,1)=Inputbox("Enter the Email")
Next
objexc.Activeworkbook.Save

objexc.worksheets(4).Name = "phone".cells(1,1)= "Phonenumber"


for L=2 To 10 Step = 1
cells(L,1)=CInt(Inputbox("Enter the phonenumber"))
Next
objexc.Activeworkbook.Save

objexc.worksheets(5).Name = "Gender".cells(1,1)= "Genderdetails"


for M=2 To 10 Step = 1
cells(M,1)=Inputbox("Enter the gender details")
Next
objexc.Activeworkbook.Save

objexc.workbooks.close

Objexcel1 = Createobject("Excel.Application")
objexc.workbooks.open("C:\New folder\Example.xlsx")
objexcel1.workbooks.open("D:\Example1.xlsx")
worksheets("Employeename").Range("Names").Copy _
worksheets("sheet1").Range("A1")

worksheets("Country").Range("Countryname").Copy _
worksheets("sheet1").Range("B1")

worksheets("Email").Range("E-id").Copy _
worksheets("sheet1").Range("C1")

worksheets("phone").Range("Phonenumber").Copy _
worksheets("sheet1").Range("D1")
worksheets("Gender").Range("Genderdetails").Copy _
worksheets("sheet1").Range("E1")

objexc.workbooks.close
objexcel1.workbooks.close
set objexc = nothing
set objexcel1 = nothing
End Sub

You might also like