在此项目中,我必须检查列B和列C之间的列A值。如果列A的值> =列B的值或列A值<=列C的值,那么我需要复制列d和e的值,并且需要分别放在工作表1的G和H列中。A列在工作表1中,而B,C,D和E列在工作表2中。
对我的措辞感到抱歉,我知道它很难理解。如果有人可以帮助我,我将永远感激不已。谢谢
A B c D E
1 1 9 Dog Naruto
11 10 19 Cat one piece
21 20 30 Duck lo
i want the outcome like this
A G H
1 Dog Naruto
11 cat One piece
21 duck lo
答案 0 :(得分:0)
只需在G和H列中分别设置一个if。
在G1中:
=IF(AND(A1<=C1,A1>=B1),D1,"")
在H1中:
=IF(AND(A1<=C1,A1>=B1),E1,"")
或者在H1中,只需检查G1中是否有一个值即可:
=IF(G1<>"",E1,"")
答案 1 :(得分:0)
这是我拥有的代码,但此代码用于检查A列的值是否等于G列的值,然后返回整行
Dim sht1 As Worksheet, sht2 As Worksheet
Set sht1 = Worksheets("sheet1")
Set sht2 = Worksheets("sheet2")
sht1= Worksheets("sheet1").Range("G" & Rows.Count).End(xlUp).Row
sht2= Worksheets("sheet2").Range("A" & Rows.Count).End(xlUp).Row
For j = 1 To sht1
For i = 1 To sht2
If sht1.Cells(j, 7).Value = sht2.Cells(i, 1).Value Then
sht1.Cells(j, 11).Resize(1, 2).Value = _
sht2.Cells(i, 1).Resize(1, 2).Value
Else
End If
Next i
Next j
End With
答案 2 :(得分:0)
请参阅以下代码(未经测试)。
Sub ColumnCheck()
Dim i As Long
Dim lRow As Long
Dim colA As Double, colB As Double, colC As Double
'assuming both sheets have the same amount of data rows
lRow = Sheets("Sheet1").Range("A" & Sheets("Sheet1").Rows.Count).End(xlUp).Row
'now loop
For i = 2 To lRow
colA = Sheets("Sheet1").Range("A" & i).Value
colB = Sheets("Sheet2").Range("B" & i).Value
colC = Sheets("Sheet2").Range("C" & i).Value
If colA >= colB Or colA <= colC Then
'if true - set values
Sheets("Sheet1").Range("G" & i).Value = Sheets("Sheet2").Range("D" & i).Value
Sheets("Sheet1").Range("H" & i).Value = Sheets("Sheet2").Range("E" & i).Value
End If
Next i
End Sub