atlas

Tom’s Tutorials For Excel: Copying Multiple ListBox Selections to Worksheet

Tom’s Tutorials For Excel: Copying Multiple ListBox Selections to Worksheet

Here’s how to transfer multiple selected items from an ActiveX ListBox onto your spreadsheet without intervening empty cells.



Private Sub cmdConfirm_Click()
'Turn off ScreenUpdating.
Application.ScreenUpdating = False

'Declare variables for row and ListBox item index.
Dim xRow As Integer, intItem As Integer

'The list will be transferred to column A.
'Clear column A to start with a clean slate.
Columns(1).Clear

'In cell A1, enter the column header and bold the cell.
With Range("A1")
.Value = "Shopping List Selections"
.Font.Bold = True
End With

'Because cell A1 is a header cell, have row 2 be the first
'row where ListBox items with start being transferred.
xRow = 2

'Open a With structure for the lbxShoppingList ListBox.
With lbxShoppingList
'Loop through each ListBox item to see if it is selected.
'If it is selected, transfer it to the next available row,
'and add a 1 to the xRow (next available row) variable.
For intItem = 0 To .ListCount - 1
If .Selected(intItem) = True Then
Cells(xRow, 1).Value = .List(intItem)
xRow = xRow + 1
End If
Next intItem
'Close the With structure.
End With

'Autofit column A for readability and neatness!
Columns(1).AutoFit

'Turn ScreenUpdating back on.
Application.ScreenUpdating = True
End Sub

Tagged , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: Summing to Today’s Date With INDIRECT

Tom’s Tutorials For Excel: Summing to Today’s Date With INDIRECT

Here’s an example of using the INDIRECT and SUM functions to add numbers from the top of column B to the row where today’s date (or whatever date you specify) is found in column A.

The formula in cell E2 is
=SUM(INDIRECT("B1:B"&MATCH(E1,A:A,0)))

If you want to bypass the helper cell for today’s date, the formula would be
=SUM(INDIRECT("B1:B"&MATCH(TODAY(),A:A,0))).

Tagged , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: SUMIF For Days Past Last Date

Tom’s Tutorials For Excel: SUMIF For Days Past Last Date

Here’s an example of two formulas working in tandem for a common goal.

In cell E1 is the formula
=LOOKUP(9.99999999999999E+307,A:A)
which returns the last number (in this case a date) in column A.

In cell E3 is the formula
=SUMIF(A5:A30,">="&(E1-E2),B5:B30)
that sums numbers in column B for dates up to 90 days past the last date.

Note that the number 90 is the criteria in cell E2.

Tagged , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: Horizontal SUMPRODUCT

Tom’s Tutorials For Excel: Horizontal SUMPRODUCT

Just a quick example of the SUMPRODUCT function being utilized for data arranged horizontally across a row, instead of the more usually-seen columnar arrangement.

The formula in cell B12 is =SUMPRODUCT((A7:L7=B10)*(A8:L8>=B11))
The formula in cell B23 is =SUMPRODUCT((A18:L18=B21)*(A19:L19=B22))

Tagged , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: Formatting Numbers and Text With Custom Colors

Tom’s Tutorials For Excel: Formatting Numbers and Text With Custom Colors

Using the familiar Format Cells dialog box and your imagination, you can totally bypass Conditional Formatting to custom-color your numbers and text as you like.



In the above picture, I have formatted positive numbers to be colored orange; negative numbers to be colored pink; a zero to be colored gray; and text to be colored brown.

As you may know, when you custom format a cell’s Number property, there are four possible entry types, separated by semicolons, in this syntax:
PostiveNumber;NegativeNumber;Zero;Text

This is why you usually see three semicolons (separating the four Number components) in custom formatting scenarios. In the next picture, the Format Cells dialog box was called by first selecting the cell(s) you want to format, and then pressing Alt+O+E

Next, click the Number tab, select Custom in the Category pane, and in the Type field enter your desired custom format. The one I entered is
[Color45][>0]#,##0;[Color7][<0]-#,##0;[Color48]0;[Color53]@

Notice I used color index numbers (45, 38, 15, and 53)instead of color names. The reason is, I wanted to demonstrate how to implement custom formats with more flexibility for selectable colors than Excel's 8 basic colors of blue, black, white, cyan, red, green, magenta, and yellow. Had I used those basic colors for example, the colors would be specified by name not index number, and the custom format would have looked different:
[Green][ > 0]#,##0;[Magenta][ < 0]-#,##0;[Yellow]0;[Blue]@

Tagged , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: Calculating Negative Time

Tom’s Tutorials For Excel: Calculating Negative Time

Here’s an example for calculating the difference between times, and expressing a negative result when a larger time is subtracted from a smaller time.



In the picture, runners are listed for comparing their 1000 meter run times against the record time. Two runners eclipsed the record, shown in column C with a negative sign in front of their calculated Over/Under time difference.

The formula in cell C7 and copied down to cell C19 is
=IF($A$4>B7,"-"&TEXT(ABS(B7-$A$4),"[hh]:mm:ss"),B7-$A$4)

The custom format in cell A4 and the cells in range B7:C19 is
[hh]:mm:ss

To call attention to the record-breakers, the data range was selected from cell A7:C19 and conditionally formatted with the custom rule
=$A$4>$B7 (note the relative and absolute references).

Tagged , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: Ranking With Conditional Omission

Tom’s Tutorials For Excel: Ranking With Conditional Omission

Here’s an example of ranking a list while omitting an item for consideration. In blue cell E2 is the name of an employee to eliminate from consideration in the ranking process.

The formula in cell C5 and copied down to cell C20 is
=IF(A5<>$E$2,SUMPRODUCT(($A$5:$A$20<>"")+0,(B5<$B$5:$B$20)+0)+1,"")

Tagged , , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: Emptying the Recycle Bin

Tom’s Tutorials For Excel: Emptying the Recycle Bin

This macro with API empties the Recycle Bin.



In a new fresh standard module:

Declare Function EmptyRecycleBin _
Lib "shell32.dll" Alias "SHEmptyRecycleBinA" _
(ByVal hwnd As Long, _
ByVal pszRootPath As String, _
ByVal dwFlags As Long) As Long

Sub RecycleBinEmpty()
Dim rbEmpty As Long
rbEmpty = EmptyRecycleBin(0&, vbNullString, 1&)
End Sub

Thanks to OnErrorGoto0 for assistance on this one.

Tagged , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: Creating a Right Click Event For ActiveX Controls

Tom’s Tutorials For Excel: Creating a Right Click Event For ActiveX Controls

Free and safe downloadable workbook example.

There is no built-in menu for the right-click event of ActiveX objects. Here is a utility for that, using a CommandButton as an example.

Tagged , , , , , , , , , , , , , , | Leave a comment

Tom’s Tutorials For Excel: Fuzzy Matching With Partial Strings For Sum or Average

Tom’s Tutorials For Excel: Fuzzy Matching With Partial Strings For Sum or Average

When you have a mish-mash of alphanumeric strings in a list, here’s how you can sum or average their corresponding numbers based on a partial string criterion.



The picture shows two examples with the criterion in cell B4.

The example on the left evaluates each item in column B for the presence of “354″ and sums for column C. The cells that match are B13, B16, and B19, so their corresponding numbers in cells C13, C16, and C19 sum to 168 in blue-colored cell C4, with array formula
=SUM(IF(ISNUMBER(FIND(B4,B7:B19,1)),C7:C19)).

The example on the right evaluates each item in column B for the presence of case insensitive “ATLAS” and averages for column C. The cells that match are B7, B8, B14, B15, and B19, with numbers in C7, C8, C14, C15, C19 averaged in pink-colored cell C4, by array formula
=AVERAGE(IF(ISNUMBER(FIND(B4,B7:B19,1)),C7:C19)).

Recall, array formulas are applied to a cell by simultaneously pressing the Ctrl+Shift+Enter keys, not just Enter. The curly braces are not typed in by you; Excel places them automatically when the array formula is properly installed.

Tagged , , , , , , , , , , , , , , | Leave a comment