Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a form that inserts an integer value in cell B2. LISTING 1 below
shows my Data Range of A2:B5. In LISTING 2, I'm trying make the sub InsertMatch() loop through each cell in Column A until it finds a cell equal to the new integer value. If a Column A cell is equal to the new integer value, I need to insert it in the Column B cell that is 1 cell to the right of the "matched" cell in Column A. If no match is found, then just insert the new integer value into cell B2. The Data Range of A2:B5 will always be growing because my form inserts a new row at B before inserting a new value. My InsertMatch sub is giving me a "Over Flow error". Can someone help me figure out why my sub InsertMatch is giving this error? So if this works, if a new integer value of 50 would be entered, it would be inserted into cell B3. Any help would be appreciated. LISTING 1: ColA ColB 45 50 60 60 75 LISTING 2: Sub InsertMatch(iValue As Integer) Dim c As Range, i As Integer Set c = ActiveSheet.Range("B2") iLastRow = getColumnLastRow("A") For i = 2 To iLastRow i = c.Row If c.Offset(0, -1).Value = iValue Then c.Value = iValue Else ActiveSheet.Range("B2") = iValue End If 'set c to the next cell down Set c = c.Offset(1, 0) Next End Sub Function getColumnLastRow(sCol As String) getColumnLastRow = ActiveSheet.Cells(Rows.Count, sCol).End(xlUp).Row End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Which criteria was matched? | Excel Discussion (Misc queries) | |||
Counting Matched Values | Excel Worksheet Functions | |||
sorting matched columns | Excel Discussion (Misc queries) | |||
Highlight Matched Rows | Excel Programming | |||
Multiple Matched Lines | Excel Discussion (Misc queries) |