Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
In a excel/VB macro I am trying compare cells in different workshe
I have two worksheets in a excel workbook. I am trying to write a macro,
using an IF statement, comparing one cell in one sheet to a cell in the other worksheet to determine what to do next? If they are equal, I want to copy some data and paste in in the other sheet. If they do not, go to the next cell and repeat test until all are satisfied. Basicall one sheet is a data input screen by individuals names. I would like to enter data, find that individual on the other sheet (a composite of all data) and paste the data. Does this make sense? Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
In a excel/VB macro I am trying compare cells in different workshe
Hi, i have did the same thing. I have one sheet "New", one sheet "Old"
and one sheet "Changes" in my file. I am comparing New with Old and then writing changed lines in Changes file in first column. same way comparing Old with New and writing changed cells in Changes sheet in second column. This is code for doing it one way. Check if it works for you. Dim ctr, N, M As Integer Dim strText1, strText2 As String N = 2 M = 2 Dim match As Boolean match = False Dim pricechanged As Boolean Application.ScreenUpdating = False Application.EnableEvents = False ' This will compare contents of sheet New with sheet Old Oldrange = Sheets("old").UsedRange.Rows.Count Newrange = Sheets("new").UsedRange.Rows.Count For Newctr = 1 To Newrange strText1 = Sheets("new").Cells(Newctr, 1).Text pricechanged = False match = False bracket1 = InStr(1, strText1, "[") If bracket1 1 Then strText1Name = Left(strText1, bracket1 - 1) For ctr = 1 To Oldrange strText2 = Sheets("old").Cells(ctr, 1).Text bracket2 = InStr(1, strText2, "[") If bracket2 1 Then strText2Name = Left(strText2, bracket2 - 1) If strText1 = strText2 Then match = True ctr = Oldrange End If If strText1Name = strText2Name Then pricechanged = True Next ctr If match = False Then Sheets("changes").Cells(N, 1) = strText1 N = N + 1 End If Next Newctr *** Sent via Developersdex http://www.developersdex.com *** |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
In a excel/VB macro I am trying compare cells in different wor
Thanks Sonu! I am a "rookie" at VB so I will work with your example to see if
I can get it to work for me. "Sonu Kamble" wrote: Hi, i have did the same thing. I have one sheet "New", one sheet "Old" and one sheet "Changes" in my file. I am comparing New with Old and then writing changed lines in Changes file in first column. same way comparing Old with New and writing changed cells in Changes sheet in second column. This is code for doing it one way. Check if it works for you. Dim ctr, N, M As Integer Dim strText1, strText2 As String N = 2 M = 2 Dim match As Boolean match = False Dim pricechanged As Boolean Application.ScreenUpdating = False Application.EnableEvents = False ' This will compare contents of sheet New with sheet Old Oldrange = Sheets("old").UsedRange.Rows.Count Newrange = Sheets("new").UsedRange.Rows.Count For Newctr = 1 To Newrange strText1 = Sheets("new").Cells(Newctr, 1).Text pricechanged = False match = False bracket1 = InStr(1, strText1, "[") If bracket1 1 Then strText1Name = Left(strText1, bracket1 - 1) For ctr = 1 To Oldrange strText2 = Sheets("old").Cells(ctr, 1).Text bracket2 = InStr(1, strText2, "[") If bracket2 1 Then strText2Name = Left(strText2, bracket2 - 1) If strText1 = strText2 Then match = True ctr = Oldrange End If If strText1Name = strText2Name Then pricechanged = True Next ctr If match = False Then Sheets("changes").Cells(N, 1) = strText1 N = N + 1 End If Next Newctr *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Using a cell's value to copy another cells info to another workshe | Excel Worksheet Functions | |||
Updating linked cells within a workbook, from worksheet to workshe | Excel Discussion (Misc queries) | |||
Create a template, on close, save those cells into another workshe | Excel Worksheet Functions | |||
How do I compare cells and if FALSE compare to next cell in EXCEL | Excel Worksheet Functions | |||
macro to compare multiple cells to determine value | Excel Worksheet Functions |