Let's see if this gets you on the right track. Your code looks very good for someone who doesn't know much, so maybe you are a quick study :)
I am confused why you are using .Offset(0, 3)
(which doesn't seem to be mentioned anywhere in your explanation) and also why you are comparing to SectorType
which is an undefined variable in the code you have provided. I am going to assume these are unnecessary, and inadvertently copied from other examples (please let me know if I'm mistaken).
I haven't tested it but I would change this assignment:
Set srcrange = Range(wb.ws2.Cells("A2:H61"))
to this, if for no other reason than it's a little more direct. I am also changing this range to only refer to column H, since that is the column round which your logic is centered (note: we can always access the other cells using Offset
and/or Resize
methods).
Set srcrange = wb.ws2.Range("H2:H61")
The meat of your logic is in this block, note removal of Row.Offset(9, 3) = SectorType
. I am also going to use a Select Case
instead of If/Then
. I find these easier to read/comprehend when there are more than one or two conditions to test:
For Each Row In srcrange.Cells '## In this case, Cells/Rows is the same, but I use Cells as I find it less ambiguous
Select Case Row.Value
Case "Not Active"
'## If the status is Not Active, Column G and H match it, and nothing needs to be done
'Do nothing
Case "In Progress", "Complete"
'## If the status is In Progress or Complete, ... copy cells A, B, and H _
' and paste it (column)"G" number of times in another worksheet - _
' within the same workbook - starting in the next available row.
'# Get the next empty cell in column A of the ws1
' I modified this to use Offset(1, 0), to return the cell BENEATH
' the last cell.
Set LastCell = wb.ws1.Cells(wb.ws1.Rows.Count, "A").End(xlUp).Offset(1)
'## copy the values from columns A, B, H to ws1
'## Column A goes in column A
LastCell.Value = Row.Offset(0, -7).Value
'## Column B goes in column B
LastCell.Offset(0, 1).Value = Row.Offset(0, -6).Value
'## Column H goes in column C (because you did not specify)
LastCell.Offset(0, 2).Value = Row.Value
End Select
Next Row