Trying to Overwrite Cell Data with VBA Macro

Status
Not open for further replies.

jdub21

New Member
Joined
Sep 19, 2022
Messages
30
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,
This is my first post and I am a moderate newb at writing VBA. I am struggling with overwriting existing cells...... Here is my scenario

Excel file with different worksheets for each state in the US (50+)
I have created 3 worksheets within the file so I can be able to have the specific records accumulate in one sheet... i.e. Onboarded, Not Interested, Still Thinking, etc.
Because of the multiple sheets, I do not have a unique identifier (ex. 1,2,3,4,5 so on for column A) was hoping to use maybe the phone column
Also I would either like to overwrite all the results in the summary sheets I created i.e. Onboarded, Not Interested, Still Thinking, etc. or have the new ones added float to the bottom.
I really need help on this because right now with this code, it just adds everything to the bottom so there are duplicates. I have added my worksheet so you can see. Also as you can see, I am writing the code for each state so if there is an easier way, i am all ears.

VBA Code:
Sub CopyOnboarded()

Dim TransIDField As Range
Dim TransIDCell As Range
Dim ATransWS As Worksheet
Dim HTransWS As Worksheet




Set ATransWS = Worksheets("AL")
Set TransIDField = ATransWS.Range("A2", ATransWS.Range("A2").End(xlDown))
Set HTransWS = Worksheets("Onboarded")

For Each TransIDCell In TransIDField

    If TransIDCell.Interior.Color = RGB(198, 239, 206) Then
       
ActiveWorkbook.Worksheets("Onboarded").AutoFilter.Sort.SortFields.Clear
       
       
        TransIDCell.Resize(1, 12).Copy Destination:= _
            HTransWS.Range("A8").Offset(HTransWS.Rows.Count - 1, 0).End(xlUp).Offset(1, 0)
           
    End If

Next TransIDCell

HTransWS.Columns.AutoFit




Set ATransWS = Worksheets("CA")
Set TransIDField = ATransWS.Range("A8", ATransWS.Range("A8").End(xlDown))
Set HTransWS = Worksheets("Onboarded")


For Each TransIDCell In TransIDField

    If TransIDCell.Interior.Color = RGB(198, 239, 206) Then
       
        TransIDCell.Resize(1, 12).Copy Destination:= _
            HTransWS.Range("A1").Offset(HTransWS.Rows.Count - 1, 0).End(xlUp).Offset(1, 0)
           
    End If

Next TransIDCell

HTransWS.Columns.AutoFit

End Sub
 
Last edited by a moderator:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Please do not mark a post as the solution, when it does not contain one. Thanks
 
Upvote 0
Duplicate to: Duplicate Cells

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

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