close

==============此為廣告欄位,與文章內容無關==============


台灣製
LOCK小醬 LOCK!兩用面紙盒護套

訂購網址:http://www.7net.com.tw/7net/rui005.faces?ID=120100154677&catid=13587&visit_chn=02&vid=ivip&mid=ivip_01&user=af000017132


==============此為廣告欄位,與文章內容無關==============

EXCEL VBA.將指定值〔依序〕由上而下填入〔指定欄位〕中
                       <.准提部林.>
-------------------------------
程式碼1:從A1開始填起,須先檢測A1是否為空格
 Sub 填入新值1()
 Dim xR As Range
 Set xR = [[Book2.xls]sheet1!A65536].End(xlUp)
 If xR <> "" Then Set xR = xR(2)
 xR = [A1]
 End Sub
 
程式碼2:從A2開始填起
 Sub 填入新值2()
 [[Book2.xls]sheet1!A65536].End(xlUp)(2) = [A1]
 End Sub
 
程式碼3:預先檢測〔Book2〕是否開啟中,若否則〔提示〕之。
 Sub 填入新值3()
 Dim xBook As Workbook, xR As Range, Jm&
 For Each xBook In Workbooks
   If LCase(xBook.Name) = "book2.xls" Then Jm = 1: Exit For
 Next
 If Jm = 0 Then MsgBox "※目標檔案未開啟! ", 0 + 16: Exit Sub
 'LCase 將檔案名稱全轉為〔小寫〕再比對(檔名大小寫也視為相異)  
 Set xR = xBook.Sheets("Sheet1").[A65536].End(xlUp)
 If xR <> "" Then Set xR = xR(2)
 xR = [A1]
 End Sub
 
程式碼4:預先檢測〔Book2〕是否開啟中,若否則〔開啟〕之。
 Sub 填入新值4()
 Dim MyBook As Workbook, xBook As Workbook, xR As Range, Jm&
 Set MyBook = ThisWorkbook
 For Each xBook In Workbooks
   If LCase(xBook.Name) = "book2.xls" Then Jm = 1: Exit For
 Next
 If Jm = 0 Then
   If Dir(MyBook.Path & "\Book2.xls") = "" Then
     MsgBox "※目標檔案不存在! ", 0 + 16: Exit Sub
   End If
   Workbooks.Open MyBook.Path & "\Book2.xls"
   Set xBook = ActiveWorkbook
   MyBook.Activate
 End If
 Set xR = xBook.Sheets("Sheet1").[A65536].End(xlUp)
 If xR <> "" Then Set xR = xR(2)
 xR = [A1]
 End Sub
-------------------------------


文章出自: http://tw.knowledge.yahoo.com/question/question?qid=1512021604108
今日特價


---------推薦每日奇摩購物中心好康商品-----------



本文內容引用自奇摩知識+,圖文版權為原所有人所有,如有任何侵權違規行為請馬上告知站長!將馬上處理!謝謝!
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 林志平 的頭像
    林志平

    stacey33的部落格

    林志平 發表在 痞客邦 留言(0) 人氣()