Posts Tagged ‘Excel’

Here’s some code that will need tweaking to fit your needs. Here I assumed the table starts in cell A1, and has no blank rows. You can adjust the values of R1,G1,B1 and R2,G2,B2 to give you the pastel shades you want.

Sub TwoColorBands()
Dim rng As Range

Dim lastCol As Long, lastRw As Long, indx As Long, ct As Long
Dim R1 As Integer, G1 As Integer, B1 As Integer
Dim R2 As Integer, G2 As Integer, B2 As Integer

lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
lastRw = Range("A" & Rows.Count).End(xlUp).Row
R1 = 200
G1 = 50
B1 = 100
R2 = 250
G2 = 75
B2 = 120
indx = 0
Set rng = Range("A1", Cells(lastRw, lastCol))
rng.Rows(1).Interior.Color = RGB(R1, G1, B1)
For Each rw In rng.Rows
    If rw.Cells(1).Value = rw.Cells(1).Offset(1, 0).Value Then
        rw.Offset(1, 0).Interior.Color = rw.Interior.Color
    ElseIf rw.Offset(1, 0).Row <= lastRw Then
        indx = indx + 1
        If indx Mod 2 <> 0 Then
            rw.Offset(1, 0).Interior.Color = RGB(R2, G2, B2)
           rw.Offset(1, 0).Interior.Color = RGB(R1, G1, B1)
        End If
    End If
Next rw
End Sub



Excel Data Validation — Introduction

Posted: Monday,November 8, 2010 in Technology
Tags: ,

What is Data Validation?

Data validation is a tool that helps you control the kind of information that is entered in your worksheet. With data validation, you can:

–provide users with a list of choices
–restrict entries to a specific type or size
–create custom settings

Note: Data validation is not foolproof. It can be circumvented by pasting data into the cell, or by choosing Edit|Clear|ClearAll 

Data Validation Dropdown
Data validation list
Provide a Drop-down List of Options

Use Data Validation to create a dropdown list of options in a cell. List items can be typed in a row or column on a worksheet, or typed directly into the Data Validation dialog box. 

1. Create a List of Items

If the list of options is more than a couple of items, it will be easier to maintain if you type the list on a worksheet. The list can be entered on the sheet that will contain the dropdown lists, or on a different sheet. In this example, the list will be stored on a sheet named Lists.

  1. In single row or column, type the entries you want to see in the drop-down list. (Note: The list must be in a single block of cells — e.g. you can use A2:A6, but not A2, A4, A6, A8.)

2. Name the List Range

If you type the items on a worksheet, and name the range, you can refer to the list from any worksheet in the same workbook.

  1. Select the cells in the list.
  2. Click in the Name box, to the left of the formula bar
  3. Type a one-word name for the list, e.g. FruitList.
  4. Press the Enter key.

Note: To create a named list that automatically expands to include new items, use a dynamic range









Name Range

3. Apply the Data Validation

  1. Select the cells in which you want to apply data validation
  2. From the Data menu, choose Validation.
  3. From the Allow drop-down list, choose List

Allow List


  1. In the Source box, type an equal sign and the list name, for example: =FruitList
  2. Click OK. 

List Source

Tip: To select a range name, instead of typing it:

  1. In the Data Validation dialog box, under Allow, select List
  2. Click in the Source box, and on the keyboard, press the F3 key
  3. From the Paste Name list, select a named range, and click OK.
  4. Click OK, to close the Data Validation dialog box.

To view the steps in a short data validation basics video, click here

Paste Name dialog box

4. Using a Delimited List

Instead of referring to a list of items on the worksheet, you can type the list in the Source box, separated by commas. For example:


Note: This method of Data Validation is case sensitive — if a user types YES, an error alert will be displayed. 


Delimited List

5. Allow Entries that are not in the List

To allow users to type items that are not in the list., turn off the Error Alert

Show Error


6. Protect the List

To protect the list from accidental damage, if you have entered it on a different worksheet, you can hide that sheet.

  1. Select the sheet that contains the list
  2. Choose Format | Sheet | Hide

Download the zipped sample workbook


Hide the Sheet