PCDVD數位科技討論區

PCDVD數位科技討論區 (https://www.pcdvd.com.tw/index.php)
-   疑難雜症區 (https://www.pcdvd.com.tw/forumdisplay.php?f=34)
-   -   [請益]這段如何改成VBA碼 (https://www.pcdvd.com.tw/showthread.php?t=988644)

fashionkid 2012-10-28 11:33 PM

[請益]這段如何改成VBA碼
 

A欄是抓取住家電話或手機末5碼作為編號,
寫入公式
=IF(ISBLANK(資料!C3),IF(ISBLANK(資料!D3),"",RIGHT((資料!D3),5)),RIGHT((資料!C3),5))
想改寫成VBA, 無奈對VBA一竅不通。上來請教各位
~~~~萬分感謝~~~

rockjimmy 2012-11-03 01:23 AM

FOR I = 1 to 100
編號= CELLS(I,3)
IF 編號="" THEN
編號= CELLS(I,4)
END IF
CELLS(I,1)= RIGHT(編號,5)
NEXT I


=================================
大概隨便寫一下
可能有錯誤
差不多就樣吧= =a

ccx1103 2012-11-03 02:45 PM

公式可以解決的問題,應該使用公式。
VBA沒有比較聰明。

Sub xxx()

Set currgn = ActiveCell.CurrentRegion
Set c = currgn.Find("*姓*名*")
If Not c Is Nothing Then
Range(c.Address).Offset(1, 0).Select
Else
Exit Sub
End If

While ActiveCell.Value <> ""
If ActiveCell.Offset(0, 1).Value <> "" Then
ActiveCell.Offset(0, -1).Value = Right(ActiveCell.Offset(0, 1).Value, 5)
End If

If ActiveCell.Offset(0, 2).Value <> "" Then
ActiveCell.Offset(0, -1).Value = Right(ActiveCell.Offset(0, 2).Value, 5)
End If

ActiveCell.Offset(1, 0).Select
Wend

End Sub


所有的時間均為GMT +8。 現在的時間是06:02 PM.

vBulletin Version 3.0.1
powered_by_vbulletin 2025。