新VBA所以請溫柔.....的Excel COUNTIF用戶輸入變量
我有重複檢查,並在列插入計數的腳本,這工作得很好,不過牀單往往不同所以我需要詢問用戶在哪一列檢查重複項以及在哪一列插入計數。我修改了腳本,但是我只是將零輸入到目標列中。我看不出有什麼問題。任何幫助都會很棒。提前致謝。
Sub LookForDuplicates()
Dim LastRow As Long
Dim column1 As String
'display an input box asking for column
column1 = InputBox(_
"Please enter column to ckeck")
'if no file name chosen, say so and stop
If Len(column1) = 0 Then
MsgBox "No column entered"
Exit Sub
End If
Dim column2 As String
'display an input box asking for column
column2 = InputBox(_
"Please enter column to insert results")
'if no file name chosen, say so and stop
If Len(column2) = 0 Then
MsgBox "No column entered"
Exit Sub
End If
'-------------------------------------------------------
「這是原來的版本我的腳本與組列偉大的工程.....不過,我需要用戶指定的列checck也哪一列將結果輸入。
'LastRow = Range("B" & Rows.Count).End(xlUp).Row
' With Range("E1")
' .FormulaR1C1 = "=COUNTIF(C2,RC[-3])"
' .AutoFill Destination:=Range("E1:E" & LastRow)
' Range("E1").Select
' ActiveCell.FormulaR1C1 = "Duplicates"
'-----------------------------------------------------
LastRow = Range(column1 & Rows.Count).End(xlUp).Row
With Range(column2 & "1")
.FormulaR1C1 = "=COUNTIF(C2,RC[-3])"
.AutoFill Destination:=Range(column2 & "1" & ":" & column2 & LastRow)
Range(column2 & "1").Select
ActiveCell.FormulaR1C1 = "Duplicates"
End With
End Sub
我不能與用戶輸入變量這方面的工作,道歉,如果我失去了一些東西,但我無法找到任何這資源....
公式:= COUNTIF($ B:$ B,B2)在宏中除外。
我需要加入這一行從類似的用戶輸入變量替換宏:= COUNTIF($列1:$ COLUMN1,column12),但我不斷收到語法錯誤。
謝謝。
我已經更新了您的意見的答案。請看看它。我用'range',因爲它相比,將代表範圍/電池串的靈活得多.. :) – bonCodigo