Six Sigma - Black Belt
here is the 1st line of code ' here is last line of code
Skip to main content
In this blog we will create multiple tabs based on the Locations. Here is the Data which we will be using to create Tabs. In this sample data, there are 10 Cities and you are tasked to create 10 Tabs with the city names. Manually it can be done. Create 10 Tabs and rename each one. Just imagine if you have 200 cities. It would be very time consuming and tiring job.
Range("A1").Select – The cursor is placed in the ‘A1’ Cell
Selection.End(xlDown).Select – The cursor is moved to the last cell in the range. In
this case ‘A11’
TotCity =
ActiveCell.Row – 1 – ‘TotCity’ is the variable
to define total city in the range.
We
minus 1 since the first row is header
and we will exclude it
Hence
Last row is 11 minus 1 = 10. Therefore TotCity would be 10
Below we will loop from 1 to10, the cities
from Bengaluru through Chandigarh in our case
For i = 1 To TotCity
TotSheet
= ActiveWorkbook.Sheets.Count – ‘TotSheet’ is the
variable to identify total number of sheets
x = i + 1 –
Sheets(1).Select
CityName =
Range("a" & x).Text – ‘CityName’ ‘ CityName’ is the variable used to pick the city
name
Sheets.Add
After:=Sheets(Sheets.Count) – ‘A new sheet is
added
Sheets(TotSheet + 1).Name =
CityName – ‘This line of code renames the last
sheet to the City
Next I - ‘Will move to next row and will loop until last city in this case ‘A11’
Chandigarh
Comments
Post a Comment