If row is green copy all date to another row

Adam_98

New Member
Joined
Sep 17, 2021
Messages
18
Office Version
  1. 365
Platform
  1. Windows
I'm quite new to Excel and I'm trying to create a document to help me for work. I have a main sheet where all my data is inputted into. The rows in this data will be Green, Amber or red depending on the status. What my goal is, when a row is green, it copies the data from one sheet to another. Is there any way to do this and is any further information needed?
 
Hello Adam,

Just my two cents worth. Try the following trimmed down code assigned to the short cut key mentioned in an earlier post:-

VBA Code:
Option Explicit
Sub Test()

        Dim wsQ As Worksheet: Set wsQ = Sheets("quotes")
        Dim wsSD As Worksheet: Set wsSD = Sheets("Spread Data")

Application.ScreenUpdating = True

        With wsQ.Range("A4", wsQ.Range("A" & wsQ.Rows.Count).End(xlUp))
                .AutoFilter 1, RGB(0, 176, 80), 8
                .Offset(1).Resize(, 27).Copy wsSD.Range("A" & Rows.Count).End(3)(2)
                '.Offset(1).Resize(, 27).EntireRow.Delete
                .AutoFilter
        End With

Application.ScreenUpdating = True

End Sub

Take heed of Joe's last post and the above should work for you.
The code also has a delete line of code included in case you want to delete the relevant rows from the 'quotes' sheet once a data transfer has been completed. It's in green font. To active this line of code, just remove the apostrophe from in front of it.

I hope that this helps.

Cheerio,
vcoolio.
Hey Vcoolio,


Thanks for chipping in with this trimmed code, it's appreciated.
I've did a bit of testing around the usability on the specific purpose on the workbook. I don't want to delete the existing information as I can use the data however when I add new information and run the Macro it duplicates the data that has already been copied over. Is there a way to stop this?

Thanks Again,

Adam
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Thanks for reviewing and spotting the Error. It's working now. Just new into coding but didn't even think something that small would impact the code so much.
You will find in programming, the small details are extremely important.
Anytime you are making a reference or doing any sort of matching, you need to match exactly (except for in cases in which you are intentionally doing an approximate or partial match).
 
Upvote 0
You will find in programming, the small details are extremely important.
Anytime you are making a reference or doing any sort of matching, you need to match exactly (except for in cases in which you are intentionally doing an approximate or partial match).
Appreciate this information and I will 100% take it on Board
 
Upvote 0
Hello Adam,

however when I add new information and run the Macro it duplicates the data that has already been copied over. Is there a way to stop this?

Hence, the delete line of code. However, if you really need to keep all the data in the source sheet, then refreshing the destination sheet would be your best option.

Place this line of code:
VBA Code:
wsSD.UsedRange.Offset(1).Clear

directly after:

VBA Code:
Application.ScreenUpdating = True

This clears the destination sheet prior to any data transfer from the source sheet meaning that you will always have both old and new data added to the destination sheet without duplication each time the code is run.

You can leave the delete line of code in place as long as you leave the apostrophe in front of it. This will keep the line of code inactive.

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Solution
Hello Adam,



Hence, the delete line of code. However, if you really need to keep all the data in the source sheet, then refreshing the destination sheet would be your best option.

Place this line of code:
VBA Code:
wsSD.UsedRange.Offset(1).Clear

directly after:

VBA Code:
Application.ScreenUpdating = True

This clears the destination sheet prior to any data transfer from the source sheet meaning that you will always have both old and new data added to the destination sheet without duplication each time the code is run.

You can leave the delete line of code in place as long as you leave the apostrophe in front of it. This will keep the line of code inactive.

I hope that this helps.

Cheerio,
vcoolio.
Thank you !! All working how I want it to work.
 
Upvote 0
You're welcome Adam. I'm glad that we were all able to chip in and help.

Cheerio,
vcoolio.
 
Upvote 0
Hello Again,

So, I've made a new sheet with the data I need and I've tried to tweak the existing code with no luck unfortunatly. It's not taking the data from the additional fields that I've added in and pasting them onto spread Data.
I've attached the VBA and the spreadsheet


VBA Code:
Option Explicit
Sub Filter_Green()

        Dim wsQ As Worksheet: Set wsQ = Sheets("Master")
        Dim wsSD As Worksheet: Set wsSD = Sheets("Spread Data")

Application.ScreenUpdating = True
wsSD.UsedRange.Offset(1).Clear

        With wsQ.Range("A9", wsQ.Range("A" & wsQ.Rows.Count).End(xlUp))
                .AutoFilter 1, RGB(0, 176, 80), 8
                .Offset(1).Resize(, 27).Copy wsSD.Range("A" & Rows.Count).End(3)(2)
                '.Offset(1).Resize(, 27).EntireRow.Delete
                .AutoFilter
        End With

Application.ScreenUpdating = True


End Sub
 
Upvote 0
Hello Adam,

I can't open your attachment but if you just require additional columns to be added then alter the 27 in this line:-

VBA Code:
.Offset(1).Resize(, 27).Copy wsSD.Range("A" & Rows.Count).End(3)(2)

to the number of columns required (the 27 takes you out to Column AA) so if its to be out to Column AB then change it to 28.

Adam,
Also, if you've changed the headings row, alter the A9 in this line of code:-

VBA Code:
With wsQ.Range("A9", wsQ.Range("A" & wsQ.Rows.Count).End(xlUp))

to whichever row the headings are now in (A8, A10??).

Cheerio,
vcoolio.
 
Last edited:
Upvote 0
I was looking for a value of AA but it all makes sense now(y). I've ran the Macro and it gets rid of all my formula and conditional formatting. Is there a way to stop this from happening so the formulas are carried onto "spread data"?
 
Upvote 0
If you want to carry over the formatting and formulae:

Change this line:-

.Offset(1).Resize(, 27).Copy wsSD.Range("A" & Rows.Count).End(3)(2)

to these two lines:-

VBA Code:
.Offset(1).Resize(, 27).Copy
wsSD.Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteAll

and add this line:-
VBA Code:
Application.CutCopyMode = False

directly above

VBA Code:
Application.ScreenUpdating = True

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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