Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.newusers
|
|||
|
|||
Worksheet_Change sub routine
I am trying to understand various points of the programme listed below and
given in a book as an example (I have deleted some of the lines of code not necessary to this question, and commented some of the lines €“ the original had no commenting):- Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim VRange As Range, cell As Range Dim Msg As String Dim ValidateCode As Variant €˜returns TRUE or text string Set VRange = Range("InputRange") €˜InputRange is defined area on spread sheet For Each cell In Target If Union(cell, VRange).Address = VRange.Address Then €˜is the cell in InputRange ValidateCode = EntryIsValid(cell) If ValidateCode = True Then Exit Sub Else €˜This outputs message of reason not valid entry End If End If Next cell End Sub Private Function EntryIsValid(cell) As Variant ' Returns True if cell is an integer between 1 and 12 or blank ' Otherwise it returns a string that describes the problem €˜ i.e. entry is Text, 12 or Not an Intiger End Function My queries are 1. Why the line Set VRange = Range("InputRange"), why not use the expression Range("InputRange") ? 2. Why For Each cell in Target, when sub routine gives only one cell reference? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VB routine to print to PDF? | Excel Worksheet Functions | |||
Sort Routine | Excel Discussion (Misc queries) | |||
simplifying routine | New Users to Excel | |||
How to create a routine | Excel Discussion (Misc queries) | |||
Solver VBA routine | Excel Discussion (Misc queries) |