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: 1
Default Trying to execute function after negative if conditional nested in For each loop

Afternoon all,

I'm trying to update one range from another, I've been pulling one cell
value from the "feed" range that I'm updating from, and then comparing
it to each cell value of the "check" range, if the value matches up,
then the feed range is re-selected, the next cell value is chosen, and
the cycle starts over again. I've managed to get this far, but I'm
trying to figure out how to write the code so that, after it compares
the "feed" value to the "check" range and doesn't find a match, then it
goes to the bottom of the "check" range and inserts a row, at which
point it will go back to the "feed" range, select the next value and
continue as before. I know the code necessary to get to the bottom of
the range and insert the row, but I can't figure out exactly where to
put it in regards to the different loops I'm using. Here's what I've
got so far:

' Open G-A-C Workbook to look up loan #'s

Workbooks.Open Filename:= _
"feed.xls" _
, UpdateLinks:=0

'Define how many new loans & how many new rows to insert

Dim Startrow As Integer
Dim Endrow As Integer
Dim Loansytd As Integer

Startrow = 10

Range("B10:B150").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select

Endrow = ActiveCell.Row

Loansytd = Endrow - Startrow

'Set up For loop

Dim loannum As String
Range("B10").Select

Dim searchfield As Range
Windows("check.xls").Activate
Set searchfield = Range("B2:B150")
Windows("feed.xls").Activate

'Start For loop

For i = 1 To Loansytd

loannum = ActiveCell.Value

Windows("check.xls").Activate
Set searchfield = Range("B2:B150")
searchfield.Activate

'Search for Loan #

For Each searchfield In Range("B2:B150")
If searchfield.Value2 = loannum Then
Windows("feed.xls").Activate
ActiveCell.Offset(1, 0).Select
Exit For
End If
Next searchfield
Next i

End Sub

I know this is probably an absolute mess, but I'd appreciate any help
or suggestions you guys (& girls) might have to offer? Once thing that
might bear mentioning:

- the sequence of the cells & values can't be disturbed, otherwise I'd
use a vlookup.

Any help is greatly appreciated!

 
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
Excel - Negative nested if then conditions TTB Excel Discussion (Misc queries) 2 February 6th 10 11:09 AM
Complicated!! - Conditional formatting with nested function JP knows excel enough to mess it up[_2_] Excel Worksheet Functions 2 September 8th 09 02:22 AM
Nested loop [email protected] Excel Worksheet Functions 1 April 5th 07 12:50 AM
ADO command.execute with a loop - only runs once George King Excel Programming 0 February 9th 06 06:24 PM
Nested Loop Frank Kabel Excel Programming 6 September 12th 04 02:41 AM


All times are GMT +1. The time now is 09:45 AM.

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"