excel A列中有一串字符,如何用VBA代码查找字符"A"出现的单元格?我想知道两个"A"之间占用了多少行???不用公式
'第ä¸ä¸ªé®é¢æå°±ä¸åçäºï¼åæ£æ¹æ³å¾å¤ï¼åçä½ çç¾åº¦ä¸é¢çé®é¢'ç¨VB6.0å°excel Aåä¸çæ°æ®èµå¼ä¸ºæ°ç»ï¼å¨è¿ä¸ªæ°ç»åºç¡ä¸å以8个æ°æ®ä¸ºåä½èµå¼ä¸ºæ°ç»ï¼å
å½¢æ大æ°ç»ååæå°æ°ç»çVB代ç æä¹åï¼è·ªæ±ï¼ï¼ï¼'åé¢æ²¡æçæï¼èªå·±ä¿®æ¹ä¸ä¸Option Explicit
Private Sub Command1_Click()
Dim s As String, arr, i As Long
s = "c:\abc.xls" 'xlsæ件ä½ç½®
If Dir(s) = "" Then
MsgBox "æªæ¾å°ï¼" & s
Exit Sub
End If
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(s)
Set xlSheet = xlBook.Worksheets
With xlSheet(1)
arr = .Range("a1:a" & .Range("A65536").End(-4162).Row) 'aåè³å°è¦æä¸ä¸ªæ°æ®ï¼æ°ç»arr读åaå
'å¨è¿éä½ å¯ä»¥ç¨vbaå代ç
End With
xlApp.DisplayAlerts = False
xlBook.Close
xlApp.Quit
For i = 1 To UBound(arr)'æå°aåä¸çæ°æ®
Debug.Print arr(i, 1),
Next
End Sub
Private Sub Command1_Click()
Dim s As String, arr, i As Long
s = "c:\abc.xls" 'xlsæ件ä½ç½®
If Dir(s) = "" Then
MsgBox "æªæ¾å°ï¼" & s
Exit Sub
End If
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(s)
Set xlSheet = xlBook.Worksheets
With xlSheet(1)
arr = .Range("a1:a" & .Range("A65536").End(-4162).Row) 'aåè³å°è¦æä¸ä¸ªæ°æ®ï¼æ°ç»arr读åaå
'å¨è¿éä½ å¯ä»¥ç¨vbaå代ç
End With
xlApp.DisplayAlerts = False
xlBook.Close
xlApp.Quit
For i = 1 To UBound(arr)'æå°aåä¸çæ°æ®
Debug.Print arr(i, 1),
Next
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-07-30
Sub xx()
Dim xRng As Range, FirstF As Range
Set FirstF = Cells.Find("A")
Set xRng = Cells.Find("A", FirstF.Offset(1, 0))
MsgBox xRng.Row - FirstF.Row
End Sub
Dim xRng As Range, FirstF As Range
Set FirstF = Cells.Find("A")
Set xRng = Cells.Find("A", FirstF.Offset(1, 0))
MsgBox xRng.Row - FirstF.Row
End Sub
第2个回答 2013-07-30
public function AinColumnA(rng,mystr) dim rng1 as range ,n% n=0for each rng1 in rng if instr(1,rng1,mystr)>0 then n=n+1 end ifnextAinColumnA=nend function 提示窗口 调用 ? AinColumnA(range("A1:A" & usedrange.rows.count),"A")