ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   In a excel/VB macro I am trying compare cells in different workshe (https://www.excelbanter.com/excel-programming/335571-excel-vbulletin-macro-i-am-trying-compare-cells-different-workshe.html)

cager

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

Sonu Kamble

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 ***

cager

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 ***



All times are GMT +1. The time now is 08:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com