VBA: Updating and Overwriting Cell Contents

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
210
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I want to create a macro to update a simple delivery DATA spreadsheet, based on the ORDER number. Not sure how to do this so that it replaces the current cell contents based on the Order # in the DATA sheet Column "I".

Criteria is listed below.

"UPDATES" sheet Column F --> "DATA" sheet Column A (Any new data based on these 2 columns data should be adding entire row to DATA after last used row)​
EXTRACT Date ONLY (MM/DD/YYYY) from "UPDATES" sheet Column T-->"DATA" sheet Column G BUT only if the word "DELIVERED" appears in Col. "T".​
"UPDATES" sheet Column X --> "DATA" sheet Column C 'extract status such as "DELIVERED"​

UPDATES Sheet:
Order #Date SentStatusAircraftDETAILSWINGDatePocusDelivery DetailsSignature
1234561-JulAC123Roses are red07/12/2020 The package was received by John Smith
1234572-JulRECEIVEDBC345Violets are blue7/4/2020
1234583-JulDE256Tow the line


DATA Sheet:
AAABBBBBBDDDEEEOrder #GGGRRRSSSmamboUUUVVVWWWmouseYYYZZZDate ReceivedStatus
1000011Apples123456alpha07/12/2020 The package was received by John SmithReceived
1000111Oranges123459beta07/14/2020 DeliveredDel
1000211Lemons123460delta07/13/2020 The package was receivedReceived
1000311Apples123461theta07/14/2020 DeliveredDel
1000411Oranges123462gamma7/16/2020 Picked up HJKIn Prog
1000511Lemons123463alpha7/17/2020 Picked up BritIn Prog
1000611Apples123464betaPicked up 7/15/2020In Prog
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hello can you please explain the question by mentioning the names of the columns related rather than mentioning as column T,F .
as it will make easier for others to understand your query and provide better solution.
 
Upvote 0
Hello can you please explain the question by mentioning the names of the columns related rather than mentioning as column T,F .
as it will make easier for others to understand your query and provide better solution.

Thanks for the feedback ER_Neha
I have updated the Criteria for you. I hope you can help. Thank you.

"UPDATES" sheet "ORDER # " (Column F) --> "DATA" sheet "ORDER # " (Column A) (Any new data based on these 2 columns data should be adding entire row to DATA after last used row)

EXTRACT Date ONLY (MM/DD/YYYY) from "UPDATES" sheet "Date Received" (Column T)-->"DATA" sheet "DATE" (Column G) BUT only if the word "DELIVERED" appears in "Date Received" (Col. "T").
"UPDATES" sheet "Status" (Column X) --> "DATA" sheet "Status" (Column C) 'extract status such as "DELIVERED"
 
Upvote 0
UPDATES" sheet "ORDER # " (Column F) --> "DATA" sheet "ORDER # " (Column A
The sheet images you are showing had Order# in Column A for UPDATES and in Column F for DATA . Which is correcct?
 
Upvote 0
The sheet images you are showing had Order# in Column A for UPDATES and in Column F for DATA . Which is correcct?
Hello JLGWhiz. My apologies for the confusion. It should be ORDER#. DATA is the sheet name. Thank you.

["UPDATES" sheet] ("ORDER # "-Column F) --> ["DATA" sheet] ("ORDER # "-Column A) (Any new data based on these 2 columns data should be adding entire row to DATA after last used row)

EXTRACT Date ONLY (MM/DD/YYYY) from ["UPDATES" sheet] ("Date Received"-Column T)-->["DATA" sheet] ("DATE"-Column G) BUT only if the word "DELIVERED" appears in ("Date Received"-Col. "T").

["UPDATES" sheet] ("Status"-Column X) --> ["DATA" sheet] ("Status"-Column C) 'extract status such as "DELIVERED"
 
Upvote 0
I'm starting to think that there is no solution to find new data and overwrite existing data in a cell. I've searched the internet for weeks and haven't seen anything.
 
Upvote 0
Hello Hope you are doing good neosez. I tried solving your query, but got stuck , as the data provided by you and the requirement given by you, both doesn't match or I am not understanding your actual requirement. Either way can be the reason. However, I tried solving the question. Please check and let me know if it works for you.
VBA Code:
Sub updating_the_data()
    Dim up As Worksheet
    Dim dt As Worksheet
    Dim i As Integer
    Dim j As Integer
    

    Set up = Sheets("Updates")
    Set dt = Sheets("Data")
    
    For i = 2 To dt.Cells(Rows.Count, 1).End(xlUp).Row
        j = up.Cells(Rows.Count, 1).End(xlUp).Row + 1
        If dt.Range("x" & i).Value = "Delivered" Then
            up.Range("c" & j).Value = dt.Range("x" & i).Value
            up.Range("g" & j).Value = dt.Range("t" & i).Value
            up.Range("a" & j).Value = dt.Range("f" & i).Value
        End If
    Next i
End Sub
 
Upvote 0
Hello Hope you are doing good neosez. I tried solving your query, but got stuck , as the data provided by you and the requirement given by you, both doesn't match or I am not understanding your actual requirement. Either way can be the reason. However, I tried solving the question. Please check and let me know if it works for you.
VBA Code:
Sub updating_the_data()
    Dim up As Worksheet
    Dim dt As Worksheet
    Dim i As Integer
    Dim j As Integer
   

    Set up = Sheets("Updates")
    Set dt = Sheets("Data")
   
    For i = 2 To dt.Cells(Rows.Count, 1).End(xlUp).Row
        j = up.Cells(Rows.Count, 1).End(xlUp).Row + 1
        If dt.Range("x" & i).Value = "Delivered" Then
            up.Range("c" & j).Value = dt.Range("x" & i).Value
            up.Range("g" & j).Value = dt.Range("t" & i).Value
            up.Range("a" & j).Value = dt.Range("f" & i).Value
        End If
    Next i
End Sub
ER_Neha Thank you so much for providing the code. However, I was unable to get it to work.

I did find this code below, on the internet. I can not get it to work. Keeps saying it's out of range. I'm too tired and I'm sure its a simple fix, but just can't see it right now.


Can someone suggest the changes required, to suit my requirement. Thank you.

VBA Code:
Sub test()
    Dim i As Integer
    k = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To k
        findvalue = ActiveSheet.Cells(i, 1).Value
        With Sheets("Update")
            l = .Cells(Rows.Count, "a").End(xlUp).Row
            Set j = .Range("A:J").Find(findvalue)
            If Not j Is Nothing Then
                .Cells(j.Row, j.Column).Offset(0, 1).Value = Sheets("Sheet1").Cells(i, 2).Value
            Else
                .Cells(l, 1).Value = Sheets("Update").Cells(i, 1).Value
                .Cells(l, 2).Value = Sheets("Update").Cells(i, 2).Value
            End If
        End With
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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