PDA

View Full Version : Solved: Check if data exists, then copy



realitybend
07-09-2008, 11:07 AM
I have a worksheet with column A containing numbers such as 123, 121, 124, 125, 127 etc. and column F containing numbers like 14.6, 32.43, 54.1, 35.6, 19.55. The rows correspond to each other (A4 is linked with F4). Where the data ends, there's just 0's. The data is updated once every two weeks.

What I need to do is copy the data that has been added to columns A and F since two weeks ago. I have the data at last weeks stopping point colored green. Then I need to paste that data in columns A and B of another sheet. How would I be able to do that? I am totally stumped.:eek:

Thanks in advance for your help.

mdmackillop
07-09-2008, 11:30 AM
Can you post your sheet?

realitybend
07-09-2008, 11:49 AM
Attatched is the file.

Thanks

mdmackillop
07-09-2008, 11:59 AM
There are no green cells.

realitybend
07-09-2008, 12:04 PM
Good point. I forgot to add them. As you can tell, this is my first time attempting to use this sheet. Anyway, I still have to add the green cells manually. Would there be a way to automatically detect the last cell and turn it green (or some other way to mark it; you would know better than I would).

Thanks.

mdmackillop
07-09-2008, 12:31 PM
With the sheet as described, I can see which Green you are using and get a solution,

realitybend
07-09-2008, 12:35 PM
It is attatched.

mdmackillop
07-09-2008, 01:08 PM
To work on the first data, you'll need to make "Number" green (colorindex 4)

Sub MakeCellGreen()
With ActiveSheet.Columns.Find(0, lookat:=xlWhole)
.Offset(-1).Font.ColorIndex = 4
.Offset(-1, 5).Font.ColorIndex = 4
End With
End Sub

Sub GetLastData()
Dim Rng As Range
Set Rng = ActiveSheet.Columns.Find(0, lookat:=xlWhole).Offset(-1)
Do
i = i - 1
Loop Until Rng.Offset(i).Font.ColorIndex = 4
Rng.Offset(i + 1).Resize(-i, 6).Copy Sheets(2).Range("A1")
End Sub

realitybend
07-09-2008, 01:19 PM
Where would I place that code?

Thanks.

mdmackillop
07-09-2008, 01:30 PM
In a standard module.

realitybend
07-10-2008, 01:11 PM
It tells me "Object Variable or width block variable not set"

.Offset(-1).Font.ColorIndex = 4

mdmackillop
07-10-2008, 03:54 PM
So why not let us see what you are working with? What is your data/fullcode?