Creating New SheetWe can create sheets by Sheets.Add and since this returns a Worksheet object, you can either name it directly:Sheets.Add.Name = "Test"or use an object and name it laterSet Sh = Sheets.AddSh.Name = "Test"Getting Sheet from name.pName = ActiveWorkbook.Path ' the path of the currently active filewbName = ActiveWorkbook.Name ' the file name of the currently active fileshtName = ActiveSheet.Name ' the name of the currently selected worksheetThe first sheet in a workbook can be referenced byActiveWorkbook.Worksheets(1)For deleting the [Report] tab you would useActiveWorkbook.Worksheets("Report").DeleteGetting name of indexed SheetshtName = ActiveWorkbook.Worksheets(1).Nameto "work on that sheet later on" you can create a range object likeDim MySheet as RangeMySheet = ActiveWorkbook.Worksheets(shtName).[A1]and continue working on MySheet(rowNum, colNum) etc. ...shortcut creation of a range object without defining shtName:Dim MySheet as RangeMySheet = ActiveWorkbook.Worksheets(1).[A1]Concatenate StringshtName = ActiveWorkbook.Worksheets(1).NameSheets.Add.Name = shtName & "mahendra"Setting font to selected CellsSelect SheetSheets("shtName").SelectSelect the Cells:ActiveCell.SelectORRows(1).SelectORColumns(2).SelectSet the Font:Selection.Font.Bold = TrueSetting value to cellCells(1, 1).Value = "Name"Getting color code for vbashowing on message dialogMsgBox CountGetting last row of excelLastRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).RowGetting Active worksheet object in excelcurrentShtName = Application.ActiveSheet.NameChanging column widthColumns("B:E").ColumnWidth = 25To autofit the columnColumns(2).AutoFitTo align a whole columnColumns("A:W").HorizontalAlignment = xlCenter
It is good to record for future references. Rather inventing solution just search the solution and if found better please update me.
Monday, April 27, 2015
Excell Programming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment