Veri Seçilmiş "gibi etiketi olacaktır 3 ay üst üste yinelenen değer varsa benim senaryonun parçası birinde bu kod Sütun A veri saymak zorunda "ve "Güncelleme"VBA - Başka Sütun hedef Sütun değiştirme
Çıktı böyle olacağını:
Column A | Column B | Column C | Column D |
243899 | 1/20/2016 | | |
243899 | 2/10/2016 | | |
243899 | 3/15/2016 | Selected | Updated |
Not:
- Sütun B olduğu aylık değeri
- "Seçilmiş" ve
- Verilerin 3 ay içinde "Güncelleme" gibi veri etiketi olacak burada Cı ve D olan sütun
sorunum beniçin
Column A
yukarıdaki örnekte tüm hedef sütun değiştirmek için gidiyorum olmasıdırColumn B
Column BS
Column C
veD
Column CH
veCI
My kodu:
Ben bu koda böylece im gerçekten aşina olmayan benim kodu varPublic Sub Selection()
Dim file2 As Excel.Workbook
Dim Sheet2 As Worksheet, data(), i&
Dim myRangeColor As Variant, myRangeMonthValue
Dim MstrSht As Worksheet
Dim DataArr As Variant
Dim ColorArr As Variant
Dim MonthCol As Collection
Dim CloseToDate As Date
Dim MaxDate As Date
Dim c As Long
Set Sheet2 = Workbooks.Open(TextBox2.Text).Sheets(1)
'Load Data into Array
DataArr = Sheet2.Range("A2:D" & Sheet2.Cells(Rows.Count, 1).End(xlUp).Row)
Find distinct colors
ColorArr = ReturnDistinct(Sheet2.Range("A2:A" & Sheet2.Cells(Rows.Count, 1).End(xlUp).Row))
Remove any values in the arrays third column
For i = LBound(DataArr, 1) To UBound(DataArr, 1)
DataArr(i, 4) = ""
Next i
'Loop Each Color
For c = LBound(ColorArr) To UBound(ColorArr)
Set MonthCol = New Collection
MaxDate = 0
For i = LBound(DataArr, 1) To UBound(DataArr, 1)
If DataArr(i, 1) = ColorArr(c) Then
'Load the colors months into a collection
On Error Resume Next
MonthCol.Add Month(DataArr(i, 2)), CStr(Month(DataArr(i, 2)))
On Error GoTo 0
'Find Max Date
If DataArr(i, 2) Then
MaxDate = Application.WorksheetFunction.Max(MaxDate, DataArr(i, 2))
End If
End If
Next i
'If the color were found in three or more seperate months then the row with date closest to CloseToDate gets flagged
If MonthCol.Count > 2 Then
For i = LBound(DataArr, 1) To UBound(DataArr, 1)
If DataArr(i, 1) = ColorArr(c) And DataArr(i, 2) = MaxDate Then
DataArr(i, 3) = "Selected"
DataArr(i, 4) = "Updated"
End If
Next i
End If
Next c
'Print results to sheet
Sheet2.Range("A2:D" & Sheet2.Cells(Rows.Count, 1).End(xlUp).Row) = DataArr
End Sub
Function ReturnDistinct(InpRng As Range) As Variant
Dim Cell As Range
Dim i As Integer
Dim DistCol As New Collection
Dim DistArr()
'Add all values to collection
For Each Cell In InpRng
On Error Resume Next
DistCol.Add Cell.Value, CStr(Cell.Value)
On Error GoTo 0
Next Cell
'Write collection to array
ReDim DistArr(1 To DistCol.Count)
For i = 1 To DistCol.Count Step 1
DistArr(i) = DistCol.Item(i)
Next i
ReturnDistinct = DistArr
End Function
.. bunu mı komutumdaki sütunu değiştirmek mümkün mü? Bu konuda bir sürü deneme ve hata yaptım, bunu anlayamıyorum. Herhangi bir yardım, ipucu veya öneri memnuniyetle takdir ediyorum!
ile başlayan olan kod sonucu birbirine bitişik olan kolonlarda nakledilen gerçeğinden yararlanır Rows.Count, 1) .End (xlUp) .Row) 'Yeni bir sütun ile belki de bir Loop ile diziye veri almak için değiştirilmelidir. 'Sheet2.Range ("A2: D") ve Sheet2.Cells (Satırlar, 1) .End (xlUp) .Row) = DataArr satırının, dizideki verileri yeni sütunlarınıza yazmak için değiştirilmesi gerekir. yine yine bir döngü ile. – OldUgly
@OldUgly teşekkürler, bu satırı değiştirmek için çalıştım defalarca bu sütunları değiştirmek gerçekten mümkün değil mi? Varsayılan olarak – 7A65726F