Category Archives: VBA

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

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

Add and remove pictures in an Excel worksheet

This is another brief foray into VBA programming. When you click the Insert Image button, the following VBA code executes. ‘ Insert a picture at the selection. Sub Button1_Click() Dim filters As String Dim filename As Variant ‘ Define the … Continue reading

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

Use VBA code to pick random cells from the currently selected cells in an Excel workbook

This example shows how you can use VBA code to pick random cells in an Excel workbook. Sooner or later, many programmers need to write code to control another application such as the Microsoft Office applications, either for their own … Continue reading

Posted in Excel, VBA | Tagged , , , , , , , , , , | 9 Comments

Make a C# DLL and use it from Excel VBA code

This example shows how to make a C# DLL and then use it from VBA code running in Excel. A similar procedure should work for other Office applications. Note that some of the steps may require modification and significant fiddling … Continue reading

Posted in Excel, interoperability, Office, VBA | 14 Comments