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: 573
Default matching 2 values with a singel value

I am comparing a list of values in 2 spreadsheets sorted on that
value. When I find a value missing in one sheet, I insert a blank row
into that sheet the corresponds to the row in the other sheet, so the
matching values in each sheet are in corresponding rows. No problem,
until I get to the end. I'm trying to figure out how to tell the macro
to enter any final rows neccessary to "match" the 2 sheets and then
end. I can easily get the highest value in the corresponding columns
(Column A in both cases) in either of the 2 sheets. But how to write
the code so that when the macro gets to that final value, it enters any
necessary corresponding blank lines to the other sheet before ending?

To start, the sheets would look like this:

Sheet A Sheet B
1 1
2 2
4 3
5 5
6 6
9 8
12

After the macro runs, they'd look like:

Sheet A Sheet B
1 1
2 2
3
4
5 5
6 6
8
9
12

Since the 12 could be in either spreadsheet and I want to put in the
blank line for the 12 in the corresponding spreadsheet, if needed, I
don't know how to end the macro or what kind of loop to use. This has
got to be a common kind of thing.

So far, I have:

Sub ClientStateIDMatchSubmital()

Dim lOrigCSID As Long
Dim lNewLstMax As Long
Dim lOrigLstMax As Long
Dim lCurRow As Long
Dim rFoundCell As Range
Dim rOrigCSID As Range
Dim rCell As Range
Dim lRow As Long
Dim lOrig As Long
Dim lNew As Long
Dim lCtySrcCol As Long
Dim lOrigCount As Long
Dim lNewCount As Long
Dim wbOrig As Workbook
Dim wbNew As Workbook
Dim lLimit As Long
Dim rNewCSID As Range
Dim wsNew As Worksheet
Dim wsOrig As Worksheet


lOrigCount = 0
lNewCount = 0

Set wbOrig = Workbooks("testorig.xls")
Set wbNew = Workbooks("testnew.xls")
Set wsOrig = wbOrig.Worksheets("sheet1")
Set wsNew = wbNew.Worksheets("sheet1")

'Determine which sheet has the highest value and set limit variable

With wsOrig
.Activate
'.Range("a2").Select
lOrigLstMax = .Cells(Rows.Count, "A").End(xlUp).Value
'Set rOrigCSID = .Range(.Cells(2, 1), .Cells(lEndRow, "A"))
End With


With wsNew
.Activate
lNewLstMax = .Cells(Rows.Count, "A").End(xlUp).Value
End With

If lNewLstMax lOrigLstMax Then
lLimit = lNewLstMax
Else
lLimit = lOrigLstMax
End If


lCurRow = 1

Do Until ????= lLimit <WHAT KIND OF LOOP, AND HOW TO END IT?

lCurRow = lCurRow + 1
lOrig = wsOrig.Cells(lCurRow, 1).Value
lNew = wsNew.Cells(lCurRow, 1).Value


If lOrig < lNew Then
If lNew lOrig Then
wbNew.Activate
wsNew.Cells(lCurRow, 1).Select
Selection.EntireRow.Insert
lOrigCount = lOrigCount + 1
Else
wbOrig.Activate
wsOrig.Cells(lCurRow, 1).Select
Selection.EntireRow.Insert
lNewCount = lNewCount + 1

End If
End If

Loop

Finish:
'Application.Run "'My Addin.xla'!MyMacro"

End Sub

Thanks in advance.

 
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
Combined cells to a singel cell cwklep Excel Worksheet Functions 1 August 6th 09 12:07 PM
can you have 2 different colors in a singel cell? Erin P Excel Discussion (Misc queries) 2 June 6th 08 03:46 AM
Finding Most Recent Values in Col1 -- Summing Matching Values Rothman Excel Discussion (Misc queries) 5 December 20th 07 08:19 PM
Mail a singel sheet i an xls file. Kirsten Excel Discussion (Misc queries) 1 June 8th 05 01:25 PM
Fill values into a listbox matching selected values from a combobox Jon[_19_] Excel Programming 4 January 25th 05 04:25 PM


All times are GMT +1. The time now is 02:05 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"