Pages

Search

Excel IT Pro Discussions Forum: I need a macro that does this (Two excel sheets shown)

Feed2Mail notification - new post on Excel IT Pro Discussions Forum
I need a macro that does this (Two excel sheets shown)

My macro worked before to do what I needed to do but for some reason it either was wrong before or I just thought it was working. Anyway here is an example of two spreadsheets, the one on the left is prior to the macro and the one on the right is after the macro. The idea is simple and below the examples I will explain my logic and show my code. Please let me know if anyone can help asap I am getting confused.

As you should be able to see from my example my macro reads out the value in Column C "WP". It then compares it to the value above in Column C and when that value changes the value in column F "Name" will copy the name of the task that started the change. So MGMT overwrote Task3 and Task because the WP value changed. It also should read the offset value and keep copying down the task name until the "WP" changes again.

Here is my code I have been trying to use. (It runs from a project user-form but it is excel mostly)

Private Sub Test()      Dim xlapp As Excel.Application   Dim NC As String, tn As String   Dim xlSheet As Worksheet   Dim c As Range      Set xlapp = GetObject(, "Excel.Application")   Set xlSheet = xlapp.ActiveWorkbook.Worksheets(1)   NC = xlSheet.UsedRange.Rows.Count   For Each c In xlSheet.Range("A2:A" & NC).Cells       Debug.Print c.Value       If c.Offset(-1, 2).Value <> "" Then           tn = c.Offset(0, 5).Value       Else           c.Offset(0, 5) = tn       End If   Next c   End Sub