Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 23rd, 2010, 01:23 AM
Authorized User
 
Join Date: Jul 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copying from worksheet to worksheet

Hello everyone. Im very new into this excel vba programming. I have two sheets namely sheet1 and sheet2 which contains details of items. Sheet 1 contains old data and Sheet2 contains updated data. All items are given a unique itemcode. I would like to copy the updated data of each and every item from sheet2 to sheet1. For example

Sheet1 -
Itemcode Name Status
item0001 Adapter Working
item0002 Monitor Working
item0003 Adapter Repair
item0004 Adapter Working
item0005 Adapter Working

Sheet2 -
Itemcode Name Status
item0001 Adapter Working
item0002 Monitor Repair
item0003 Adapter Scrap

I want to update the status of Items(around 3000 items) in sheet1. I want excel to search for itemcodes in sheet1 that is in sheet2 and update their status. Urgent Please help. This is for my project purpose. Thankyou All.

Last edited by millenniumbuddy; August 23rd, 2010 at 02:31 AM..
Reply With Quote
  #2 (permalink)  
Old August 23rd, 2010, 03:08 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Here is a hint:

Code:
Sub Find_Replace_Example()
Dim oCell As Range
Dim oColBMatch As Range
 
For Each oCell In Worksheets(1).Range("A1:A3000")
    
    sText = oCell.Value
    
    If Len(sText) <> 0 Then
    
    
    Set oColBMatch = Worksheets(2).Range("A:A").Find(What:=sText, Lookat:=xlWhole)
    If Not oColBMatch Is Nothing Then
        oCell.Offset(0, 2).Value = Worksheets(2).Cells(oColBMatch.Row, 3).Value
    End If
Next oCell
End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #3 (permalink)  
Old August 23rd, 2010, 07:13 AM
Authorized User
 
Join Date: Jul 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Hello...

Thanks a lot Shasur for supporting me. I still have an issue with that code. I dont get any errors but sheet1 still isnt updated the data(status) is as it is.

Sub FindReplace1()
Dim oCell As Range
Dim oColBMatch As Range

For Each oCell In Worksheets(1).Range("A2:A3000")

sText = oCell.Value

If Len(sText) <> 0 Then


Set oColBMatch = Worksheets(2).Range("A2:A3000").Find(What:=sText, Lookat:=xlWhole)
If Not oColBMatch Is Nothing Then
oCell.Offset(0, 2).Value = Worksheets(2).Cells(oColBMatch.Row, 3).Value
End If
End If
Next oCell

End Sub

Sheet1
Itemcode Name Status
item0001 Adapter Working
item0002 Monitor Working
item0003 Adapter Repair
item0004 Adapter Working
item0005 Adapter Working

Sheet2
Itemcode Name Status
item0001 Adapter Working
item0002 Monitor Repair
item0003 Adapter Scrap
Reply With Quote
  #4 (permalink)  
Old August 23rd, 2010, 08:05 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

The code takes value from Sheet 1 and searches in Sheet 2. If you find something in Sheet 2 it copies it

If you have different order you can try the following

Sub FindReplace1()
Dim oCell As Range
Dim oColBMatch As Range

For Each oCell In Worksheets("Sheet1").Range("A2:A3000")

sText = oCell.Value

If Len(sText) <> 0 Then


Set oColBMatch = Worksheets("Sheet2").Range("A2:A3000").Find(What:= sText, Lookat:=xlPart)
If Not oColBMatch Is Nothing Then
oCell.Offset(0, 2).Value = Worksheets(2).Cells(oColBMatch.Row, 3).Value
End If
End If
Next oCell

End Sub

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #5 (permalink)  
Old August 23rd, 2010, 10:01 AM
Authorized User
 
Join Date: Jul 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hi

Great! Now that worked. Thanks a lot
Reply With Quote
  #6 (permalink)  
Old August 24th, 2010, 01:38 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Glad to hear that.

Happy coding :)

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copying input data to another worksheet with code kwik10z Excel VBA 3 November 2nd, 2007 01:45 PM
Copying Rows to New worksheet eusanpe Excel VBA 7 December 21st, 2006 10:23 AM
finding a worksheet ozPATT Excel VBA 4 November 16th, 2005 10:54 AM
Email Worksheet alannoble26 Excel VBA 2 November 7th, 2005 10:33 AM
Send Worksheet alannoble26 Excel VBA 3 November 2nd, 2005 01:04 PM



All times are GMT -4. The time now is 10:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.