Tutorial by Examples

In many Excel applications, the VBA code takes actions directed at the workbook in which it's contained. You save that workbook with a ".xlsm" extension and the VBA macros only focus on the worksheets and data within. However, there are often times when you need to combine or merge data fr...
It's a VBA Best Practice to always specify which workbook your VBA code refers. If this specification is omitted, then VBA assumes the code is directed at the currently active workbook (ActiveWorkbook). '--- the currently active workbook (and worksheet) is implied Range("A1").value = 3.1...
If you want to access a workbook that's already open, then getting the assignment from the Workbooks collection is straightforward: dim myWB as Workbook Set myWB = Workbooks("UsuallyFullPathnameOfWorkbook.xlsx") If you want to create a new workbook, then use the Workbooks collection o...
Often saving new data in an existing workbook using VBA will cause a pop-up question noting that the file already exists. To prevent this pop-up question, you have to suppress these types of alerts. Application.DisplayAlerts = False 'disable user prompt to overwrite file myWB.SaveAs FileNa...
The "factory default" number of worksheets created in a new Excel workbook is generally set to three. Your VBA code can explicitly set the number of worksheets in a new workbook. '--- save the current Excel global setting With Application Dim oldSheetsCount As Integer oldSheets...

Page 1 of 1