Abdoon
05-21-2013, 12:52 PM
Hey everyone,
I am having trouble with a program i'm trying to write in vba. I didn't think it would be too complicated, but I haven't worked much with programming in excel and don't know all the correct verbiage compared to C (which I know much better).
So I have a spreadsheet with a list of different items (i.e. projects being worked on) in one column of sheet 2. An example of what is seen in the projects column is shown below
Projects
Charitable Donation
Charitable Donation
Charitable Donation
Special Offers Page
Special Offers Page
The reason they are listed more than once is because that is how the spread sheet is listed (that's where the challenge for me comes in). What I am attempting to do is copy the "projects" column from sheet 2 into sheet 1, BUT without having more than one copy of the duplicate projects. For example, I want to copy just one "Charitable Donation", and one "Special Offers Page".
Here's what I have so far, I just don't know what to do in order to get just one copy of each project. I am currently getting all copies of all projects.
Sub projects()
For i = 1 To 1000
Sheets("Data").Activate
If Cells(i + 1, 9) <> Cells(i, 9) Then Cells(i + 1, 9).Copy
Sheets("Metrics").Select
Cells(i, 1).Select
ActiveSheet.Paste
Next i
For i = 1 To 1000
Sheets("Metrics").Select
If Cells(i, 1) = Cells(i + 1, 1) Then Cells(i, 1).EntireRow.Delete
Next i
End Sub
*Note - Sheet 1 is "Metrics" and Sheet 2 is "Data".
Any help would be greatly appreciated, hope this makes sense. Its mainly the second "For" loop that I'm not sure how to write. Thanks!
I am having trouble with a program i'm trying to write in vba. I didn't think it would be too complicated, but I haven't worked much with programming in excel and don't know all the correct verbiage compared to C (which I know much better).
So I have a spreadsheet with a list of different items (i.e. projects being worked on) in one column of sheet 2. An example of what is seen in the projects column is shown below
Projects
Charitable Donation
Charitable Donation
Charitable Donation
Special Offers Page
Special Offers Page
The reason they are listed more than once is because that is how the spread sheet is listed (that's where the challenge for me comes in). What I am attempting to do is copy the "projects" column from sheet 2 into sheet 1, BUT without having more than one copy of the duplicate projects. For example, I want to copy just one "Charitable Donation", and one "Special Offers Page".
Here's what I have so far, I just don't know what to do in order to get just one copy of each project. I am currently getting all copies of all projects.
Sub projects()
For i = 1 To 1000
Sheets("Data").Activate
If Cells(i + 1, 9) <> Cells(i, 9) Then Cells(i + 1, 9).Copy
Sheets("Metrics").Select
Cells(i, 1).Select
ActiveSheet.Paste
Next i
For i = 1 To 1000
Sheets("Metrics").Select
If Cells(i, 1) = Cells(i + 1, 1) Then Cells(i, 1).EntireRow.Delete
Next i
End Sub
*Note - Sheet 1 is "Metrics" and Sheet 2 is "Data".
Any help would be greatly appreciated, hope this makes sense. Its mainly the second "For" loop that I'm not sure how to write. Thanks!