У меня есть некоторый код, который работал нормально на протяжении многих лет, теперь мои данные прошли через столбец z, и код больше не работает, как только он проходит мимо столбца z, значение строки ранжирования равно [29, а не AA29, AB29 и т. Д.Может ли кто-нибудь дать мне руководство о том, как я могу сделать эту работу, нужно перейти хотя бы к столбцу AW.другие люди сказали мне, что я сделал фундаментальную ошибку, потому что я должен был использовать номера столбцов, а не имена.Я не эксперт, и мне удалось заставить это работать, каннибализируя код, который я нашел здесь и в других местах.Мой код ниже, надеюсь, это понятно.
Sub Copy_picked_X1s_to_final_56()
Dim SelectedName() As String 'this array holds the "SelectedName" for a specific date
Dim AllNames() As Variant 'this array holds all the names in the "Final Assignments"
Dim NameCount1 As Long, NameCount2 As Long 'namecount 1 holds a count of the "SelectedName", namecount 2 holds a count of "AllNames" in the "Final Assignments"
Dim Services() As Variant 'this array holds a list of all the "Services"
Dim Columncounter As Long 'this array holds a count of all the columns that have "Services"
Dim NameCell As String 'this string holds the location of the cell in "Final Assignments" where the "SelectedName" appears
Dim location As String
Dim Name1 As String
Dim Name2 As String
Dim NameFound As Long
Dim FillArray As Long 'used to loop through the various arrays
Dim RangeString As String
Dim ServiceCount As Long
'***********************************************************************************************'
' Fill the services array with the full list of services and loop through the services
'***********************************************************************************************'
Sheets("Final Assignments").Select 'select "Final Assignments" worksheet
ServiceCount = Range("B3", Range("B3").End(xlToRight)).Cells.Count - 1 'set range of "Services" to count
ReDim Services(0 To ServiceCount) 'Redimension the "Services" array
For Columncounter = 0 To ServiceCount
'Services(Columncounter) = Range("B3").Offset(0, Columncounter).Value 'collect the values
Next Columncounter
'***********************************************************************************************'
' Loop through all the services
'***********************************************************************************************'
For Columncounter = 0 To ServiceCount
Sheets("Sorted X1").Select 'select "Sorted X1" worksheet
RangeString = Chr(65 + Columncounter) & "29" 'set the range based on the columncounter
NameCount1 = Range(RangeString, Range(RangeString).End(xlDown)).Cells.Count - 1 'count the number of names for the first date
ReDim SelectedName(0 To NameCount1) 'Redimension the "SelectedName" array
If SelectedName(0) = "" And SelectedName(1) = "" And NameCount1 = 1 Then
For FillArray = 0 To NameCount1 'gather the names
SelectedName(FillArray) = Range(RangeString).Offset(FillArray).Value
Next FillArray
End If
'***********************************************************************************************'
'Now select the first name in the final assignments list
'***********************************************************************************************'
Sheets("Final Assignments").Select 'select "Final Assignments" worksheet
NameCount2 = Range("A4", Range("A4").End(xlDown)).Count - 1 'count the number of "AllNames" in the "Final Assignments"
Range("A3").Select
If NameCount1 < 4 Then
For NameFound = 0 To NameCount2
ActiveCell.Offset(1, 0).Select
For FillArray = 0 To NameCount1
If SelectedName(FillArray) = ActiveCell.Value Then
ActiveCell.Offset(0, Columncounter + 1).Value = "X1" 'Services(Columncounter)
End If
Next FillArray
Next NameFound
End If
Next Columncounter 'increment along the row
End Sub