LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Insert Matched Value

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which criteria was matched? Justin Larson[_2_] Excel Discussion (Misc queries) 0 February 18th 10 04:24 PM
Counting Matched Values Pepper Excel Worksheet Functions 3 November 18th 08 02:43 AM
sorting matched columns Shiela Excel Discussion (Misc queries) 2 November 14th 08 05:16 AM
Highlight Matched Rows Sean Excel Programming 5 October 9th 07 05:01 PM
Multiple Matched Lines Mark Philley Excel Discussion (Misc queries) 7 November 22nd 06 02:41 AM


All times are GMT +1. The time now is 10:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"