Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
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
Using a cell's value to copy another cells info to another workshe badger2407 Excel Worksheet Functions 1 March 16th 10 09:21 PM
Updating linked cells within a workbook, from worksheet to workshe notloiseweiss Excel Discussion (Misc queries) 7 February 18th 08 01:15 AM
Create a template, on close, save those cells into another workshe kangasnat Excel Worksheet Functions 1 March 5th 07 05:47 PM
How do I compare cells and if FALSE compare to next cell in EXCEL Cindie Excel Worksheet Functions 0 March 24th 06 05:29 PM
macro to compare multiple cells to determine value macrodummy Excel Worksheet Functions 2 October 9th 05 01:21 PM


All times are GMT +1. The time now is 05:41 AM.

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

About Us

"It's about Microsoft Excel"