昨天我问了一个关于检查A列值的问题。我得到了一些很好的答案,但它是基于我检查的值在列中彼此相邻,如D3874 BGE XS,I3874 BGE列中的XS,其值为
D3875 HMG XS
D3875 BGE XS
D3874 BGE XS
I3874 BGE XS
经过som测试后,似乎我需要从一个新的角度来解决这个问题。
我的专栏也有行,看起来像
D3875 HMG XS
D3840 BGE XS
D3871 BGE XS
I3875 BGE XS
I3875 HMG XS
我想要做的就是编写一个循环,在行中接受I或D旁边的值,如3875,然后我想通过列运行此直到我找到相同的值来代替我D的开头然后打印决定在第一个值旁边。
基本上我想让我的代码做的是检查I或D之后的4位数字和se是否有相同4位数的单元格,但是开头是I而不是D.它检查单元格D3875 HMG XS我想使用nr 3875来查看我是否能找到值为I3875的单元格。
我的代码知道的是这个但是我的技能达到了高峰(6小时),我无法让它工作。
Sub leta_PU()
Dim dataworksheet As Worksheet
Dim leta As String
Dim name As String
Dim flik As Worksheet
Dim i As Integer
Set dataworksheet = ActiveWorkbook.Worksheets("Sheet1")
Dim Project3 As String
Dim Project1 As String
Dim Project2 As String
Set flik = dataworksheet
leta = dataworksheet.Cells(i, 2).Value
Project1 = Left(leta, 5)
Project2 = Right(milsten1, 4)
Project3 = "I" & Project2
Debug.Print (Project3)
Dim statuskolumn As Long
statuskolumn = rowNRAMTstatus(Project3, flik)
Debug.Print ("Statuskolumn= " & statuskolumn)
Dim dagensstatus As Variant
dagensstatus = dataworksheet.Cells(rad, statuskolumn).Value leveranssheet.Cells(i, 2).Value = dagensstatus
If leveranssheet.Cells(i, 2).Value >= 1 Then
leveranssheet.Cells(i, 3).Value = "Decided"
Else
leveranssheet.Cells(i, 3).Value = "Not Decided"
End If
End Sub
我想检查A列中值的函数rowNRAMTstatus是
Function rowNRASMTstatus(namn As String, sourceWS As Worksheet) As Integer
Dim antalrader As Integer
Dim rad As Integer
Dim rowname As String
Dim lstrow As ListColumn
'Debug.Print
With sourceWS
antalrader = .Range("a" & Rows.Count).End(xlUp).Row
For i = 1 To antalrader
Set lstrow = .Cells(1, i)
rowname = lstrow.Value
'Debug.Print (rowname)
If rowname Like namn & "*" & "U" Then ' If kolname = "*" & namn Then
Debug.Print ("Får träff på kolumnnamn " & namn & " i kolumn " & kolname)
rad = i
'Debug.Print ("Som har nr " & kolumn)
Exit For
End If
Next i
End With
rowNRASMTstatus = rad
'Debug.Print (kolumnNR)
End Function