

Sub sbClearEntireSheet() Sheets("SheetName").Cells.Clear End Sub Clearing Only Data from Worksheet using ClearContents Method This method will clear entire worksheet including formats. This method will clear only clear the content or data of the range not formats (Formats remain same) Sub sbClearCellsOnlyData() Range("A1:C10").ClearContents End Sub Clearing Entire Worksheet using Clear Method Sub sbClearCells() Range("A1:C10").Clear End Sub Clearing Only Data of a Range using ClearContents Method Press F5 to run it Now you should see the required data (from Range A1 to B10 ) is copied to the target range (Range E1 to F10). Save the file as macro enabled workbook 7.
Excel vba examples pdf code#
Copy the above code and Paste in the code window 6. 'Then we paste in the active sheet, so that it will paste from active range Application.CutCopyMode = False End Subġ. 'Method 2 Range("A1:B10").Copy Range("E1").Select ActiveSheet.Paste 'In the second method, first we copy the source data range 'Then we select the destination range 'Target can be either one cell or same size of the source range. 'Target can be either one cell or same size of the source range. Sub sbSelectARange() 'You can also use Range Object Range("C3").Select 'Collection of Cells OR Multiple Cells = Range Range ("B2:C4").Select ' It will Select B2,B3,B4,C2,C3,C4 End Sub 'In this example I am Copying the Data from Range ("A1:B10") to Range(E1") Sub sbCopyRange() 'Method 1 Range("A1:B10").Copy Destination:=Range("E1") 'Here the first part is source range, 'and the second part is target range or destination. In this example I am selecting a Range using Select method of Range. Sub sbGetCellData() MsgBox Cells(1, 1) 'Here the first value is Row Value and the second one is column value 'Cells(1, 1) means first row first column End Sub

In this example I am reading the data from first Cell of the worksheet. Sub sbReadWriteCellExample1() 'Using Cell Object Cells(5, 3) = Cells(3, 2) MsgBox Cells(5, 3) End Sub In this example I am reading the data from Range B3 and Writing the data into C5 using Cell Object. Sub sbWriteIntoCellData() Cells(1, 1)="Hello World" 'Here the first value is Row Value and the second one is column value 'Cells(1, 1) means first row first column End Sub In this example I am writing the data to first Cell of the Worksheet.
