Category Archives: Excel

Use VBA code to pick random cells from a filtered selection in an Excel workbook

This example shows how you can use VBA code to pick random cells in an Excel workbook when the selected cells are filtered. The post Use VBA code to pick random cells from the currently selected cells in an Excel … Continue reading

Posted in Excel, VBA | Tagged , , , , , , , , , , | Leave a comment

Use VBA to make a Gantt chart showing work schedules

This example shows how to use VBA (Visual Basic for Applications) in an Excel workbook to draw a Gantt chart showing when employees are scheduled to work. This isn’t C# programming, but you may find it useful. (And I don’t … Continue reading

Posted in Excel, VBA | Tagged , , , , , , , , | Leave a comment

Use VBA to randomize Excel selections

The post Use VBA to randomize cells in Excel explains how you can randomize a simple selection’s rows. Unfortunately that method cannot randomize Excel selections in general. In particular it doesn’t work if the current selection includes multiple areas on … Continue reading

Posted in Excel, VBA | Tagged , , , , , , , , , , | Leave a comment

Understand range areas in Excel VBA

Most of my VBA examples assume that the current selection is a single block of cells. If the selection includes a single area, then you can easily loop through the cells that it contains. Unfortunately if the selection includes multiple … Continue reading

Posted in Excel, VBA | Tagged , , , , , , , , , | 1 Comment

Load Excel records into a DataGridView in C#

This example shows how you can load Excel records into a DataGridView control. You can use similar techniques to load Excel data into other controls such as other kinds of grid controls or a TreeView control. This example uses the … Continue reading

Posted in controls, database, Excel, interoperability | Tagged , , , , , , , , , , , , | 11 Comments

Use VBA macros to add hyperlinks to external files

My book Essential Algorithms: A Practical Approach to Computer Algorithms has associated instructor materials that include lesson plans and PowerPoint presentations that are accessible via hyperlinks. The materials include a summary Excel workbook that contains hyperlinks that let you open … Continue reading

Posted in Excel, Office, PowerPoint, Word | Tagged , , , , , , , , , , , , , | Leave a comment

Use VBA to randomize cells in Excel

This is quick excursion into Excel VBA programming. This example uses a VBA macro to let you randomize the selected cells in an Excel workbook. If you select a contiguous block of cells and click the Randomize button, the following … Continue reading

Posted in Excel, Office, VBA | Tagged , , , , , , , , , , , , , | 4 Comments

Save Excel data in a PDF file in C#

This example extends the example Write Excel data in C#. See that example for information on how to open an Excel workbook, write data into it, and save it. Note that before you can use the Excel interop library, you … Continue reading

Posted in Excel, Office | Tagged , , , , , , , , , , | 6 Comments

Load a CSV file in Excel in C#

Loading a CSV file (comma-separated value file) into Excel isn’t too hard once you know the tricks. Using the same tricks you can load a file that uses any delimiter, not just a comma. First at design time, add a … Continue reading

Posted in Excel, files, Office | Tagged , , , , , , , , , , , , | 5 Comments

Make an Excel chart in C#

This example uses the following code to create an Excel chart in a new workbook. private void btnCreateChart_Click( object sender, EventArgs e) { // Get the Excel application object. Excel.Application excel_app = new Excel.ApplicationClass(); // Make Excel visible (optional). excel_app.Visible … Continue reading

Posted in Excel, interoperability, Office | Tagged , , , , , , , , , , | 1 Comment