У меня есть следующий макрос. Я использую его для выборки строк, но хочу отредактировать его, чтобы пропустить уже выбранные строки. Кто-нибудь может предложить решение?
Sub GenerateSample()
Dim all As Range
Dim selRange As Range
Dim output() As Integer
interval = Evaluate(Names("SampleInterval").Value)
'Sampling
''Select all POPULATION transactions
Set all = Sheets("Population").Range("Population")
Set last_cell = GetLastCell(all, xlByRows)
Set p = Range(all.Cells(2), last_cell)
'for debuging
'MsgBox (p.Count)
''To set random starting point
Randomize
Lower = 0
sampling = Int((interval - Lower + 1) * Rnd + Lower)
cnt = 2
accumulator = p.Cells(2).Value
Do Until cnt >= p.Count
'' Sampling when count there
If accumulator < sampling Then
cnt = cnt + 1
accumulator = accumulator + Abs(p.Cells(cnt).Value)
Else
ret = AppendArray(output, cnt)
sampling = sampling + interval
End If
Loop
' End of Sampling
'Prepare Sample Listing output area
Set selRange = Sheets("Main").Range("SAMPLEAREA_LIST")
ttl_rows = selRange.Rows.Count
rows_needed = UBound(output)
'' Insert rows if it is less than needed.
If ttl_rows < rows_needed Then
Cells(selRange.Row, 1).Activate
For i = ttl_rows To rows_needed
ActiveCell.Offset(1).EntireRow.Insert
Next i
End If
'' Delete rows if it is more than needed.
If ttl_rows > rows_needed Then
Cells(selRange.Row, 1).Activate
For i = ttl_rows To rows_needed + 1 Step -1
ActiveCell.Offset(1).EntireRow.Delete
Next i
End If
selRange.ClearContents
For i = 1 To rows_needed
''' print sample number
Cells(selRange.Row + i - 1, 2).Value = i
''' print reference number
Cells(selRange.Row + i - 1, 3).Value = Sheets("Population").Cells(output(i), 1)
''' print date
Cells(selRange.Row + i - 1, 4).Value = Sheets("Population").Cells(output(i), 2)
''' print amount
Cells(selRange.Row + i - 1, 5).Value = Sheets("Population").Cells(output(i), 3)
''' prepare calculation for misstatementprint amount
Cells(selRange.Row + i - 1, 7).Formula = "=ABS(RC[-2])-ABS(RC[-1])"
''' prepare calculation for % of misstatementprint
Cells(selRange.Row + i - 1, 8).Formula = "=RC[-1]/RC[-2]"
Next i
selRange.Columns(2).NumberFormat = "General"
selRange.Columns(3).NumberFormat = "General"
selRange.Columns(4).NumberFormat = "yyyy-mm-dd"
selRange.Columns(5).NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End Sub