From sheet A to B

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
379
Office Version
  1. 365
Platform
  1. Windows
Good morning,

For me this is a very big challenge. Let me explain.
Got two sheets and lets name them Sheet1 and Sheet2, these are different files.

In Sheet1 I have 3 columns, A B and C. A containing an item code, B description and C a price. What I need to be happening is that the when I push a button all the rows will copied to Sheet2, but in Sheet2 there are more rows present so in Sheet2 the item code must be found in column A of Sheet 2 and then the whole row must be overwritten. Then in columns D the date and time has to be filled.

Is that possible to make?

Thank you for your time and effort,

Kind regards,

Romano
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
Sub UpdPrices()
Const kSRC = "Sheet1"
Const kTARG = "Sheet2"
Dim vCode
Dim r As Long
On Error GoTo errFind
Sheets(kSRC).Activate
Range("A2").Select
While ActiveCell.Value <> ""
   vCode = ActiveCell.Value
   r = ActiveCell.Row
   
    Sheets(kTARG).Activate
    Range("A1").Select
    Cells.Find(What:=vCode, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
     
   Sheets(kSRC).Activate
   Rows(r & ":" & r).Copy
   Sheets(kTARG).Activate
   ActiveSheet.Paste
   'set time
   ActiveCell.Offset(0, 3).Value = Now()
   Sheets(kSRC).Activate
   Application.CutCopyMode = False
   
   ActiveCell.Offset(1, 0).Select 'next row
Wend
Exit Sub
errFind:
If Err = 91 Then  'code not found, paste at btm
   Selection.End(xlDown).Select
   ActiveCell.Offset(1, 0).Select 'next row
   Resume Next
Else
MsgBox Err.Description, , Err
End If
End Sub
 
Upvote 0
Solution
Code:
Sub UpdPrices()
Const kSRC = "Sheet1"
Const kTARG = "Sheet2"
Dim vCode
Dim r As Long
On Error GoTo errFind
Sheets(kSRC).Activate
Range("A2").Select
While ActiveCell.Value <> ""
   vCode = ActiveCell.Value
   r = ActiveCell.Row
  
    Sheets(kTARG).Activate
    Range("A1").Select
    Cells.Find(What:=vCode, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    
   Sheets(kSRC).Activate
   Rows(r & ":" & r).Copy
   Sheets(kTARG).Activate
   ActiveSheet.Paste
   'set time
   ActiveCell.Offset(0, 3).Value = Now()
   Sheets(kSRC).Activate
   Application.CutCopyMode = False
  
   ActiveCell.Offset(1, 0).Select 'next row
Wend
Exit Sub
errFind:
If Err = 91 Then  'code not found, paste at btm
   Selection.End(xlDown).Select
   ActiveCell.Offset(1, 0).Select 'next row
   Resume Next
Else
MsgBox Err.Description, , Err
End If
End Sub
Good afternoon, this really helps in the right direction. Thank you for your efforts,

Kind reagrds,

Romano
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,993
Members
448,539
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top