Excel VBA将列与输入值进行比较
我不喜欢excel宏,我正在尝试制作一个类似以下的宏: 我想输入一些数字,并将其与列中的值进行比较 例: excel中的列具有: 1234 1233 1236 我的意见是: 1234 结果: B列 1>1234-1234(查找一次) 0>1234-1233(不同) 0>1234-1236(不同) C列 1233>与输入不同的第一个值 1236>与输入不同的第二个值 现在我只知道如何输入值:(类似这样的内容:Excel VBA将列与输入值进行比较,vba,excel,Vba,Excel,我不喜欢excel宏,我正在尝试制作一个类似以下的宏: 我想输入一些数字,并将其与列中的值进行比较 例: excel中的列具有: 1234 1233 1236 我的意见是: 1234 结果: B列 1>1234-1234(查找一次) 0>1234-1233(不同) 0>1234-1236(不同) C列 1233>与输入不同的第一个值 1236>与输入不同的第二个值 现在我只知道如何输入值:(类似这样的内容: Sub getInput() MyInput = InputBox("Ente
Sub getInput()
MyInput = InputBox("Enter Number")
MsgBox ("Searching") & MyInput
End Sub
我找到了答案,所以我将与大家分享
Sub getInput()
Dim i As Integer ' Integer used in 'For' loop
Dim x As Integer
Dim total As Integer
Dim save As Integer
Do
MyInput = InputBox("Enter Number")
If MyInput = "" Then
Exit Sub
Else
MsgBox ("Searching ") & MyInput
total = 0
x = 2
y = x + 1
For i = 1 To 3 'hardcode - 3 because I have 3 value in A
Cells(i, y).Value = ""
If Int(Cells(i, 1).Value) = Int(MyInput) Then
' A match has been found to the supplied string
' Store the current row number and exit the 'For' Loop
total = total + 1
If Cells(i, x).Value = 0 Then
Cells(i, x).Value = Int(total)
Else
Cells(i, x).Value = Int(Cells(i, x).Value) + Int(total)
End If
Else
Cells(i, y).Value = Cells(i, 1).Value
End If
Next i
' Pop up a message box to let the user know if the text
If total = 0 Then
MsgBox "String " & MyInput & " not found"
Else
MsgBox "String " & MyInput & " found"
End If
x = x + 1
End If
Loop Until MyInput = "" 'Loop until user press cancel or input blank data
End Sub
尝试通过输入框先输入一个值到工作表。
希望能有帮助
Sub Macro1()
Dim myformula As String
Dim lr As Long
With Sheets(1)
lr = .Cells(.Rows.Count, "A").End(xlUp).Row
Range("p1").Value = Application.InputBox("Enter Number", , , , , , 1)
Range("B1").Select
myformula = "=IF(R1C16=RC[-1],1,0)"
Range("b1").Formula = myformula
Selection.AutoFill Destination:=Range("B1:B" & lr), Type:=xlFillDefault
Range("C1").Select
ActiveCell.FormulaR1C1 = "=IF(C[-1]=0,C[-2],"""")"
Selection.AutoFill Destination:=Range("C1:C" & lr), Type:=xlFillDefault
End With
End Sub
你不能让用户在单元格中输入它,然后使用公式得到你想要的吗?我正在尝试为此制作一个宏,我可以将输入输入到单元格中,但不知道现在该做什么:(a列是否有重复项?
1>1234-1234(查找一次)
因此,如果1234在A列中重复5次,那么在每个实例中,您希望B列中出现5次?或者您希望在B列中出现dup?SiddharthRout 5的任何地方都显示1