返回列表 上一主題 發帖

[發問] VBA 自動插入至空白格方式

回復 2# lichang


    你如果能夠敘述的更明確一點,甚或舉出完整的例子來,大家會比較好幫忙你,
    因為你說明的太少了,讓人摸不著頭緒,不知道該如何幫忙。

TOP

回復 4# lichang


    幫補自動排序
  1. Private Sub CommandButton1_Click()
  2. Dim Col As Integer
  3. Col = Sheets("工作表1").[a1].End(xlToRight).Column + 1
  4. Cells(1, Col) = TextBox1.Value
  5. Cells(2, Col) = TextBox2.Value
  6. Cells(3, Col) = TextBox3.Value
  7. Range(Cells(1, 2), Cells(3, [XFD3].End(1).Column)).Select
  8. Selection.Sort Key1:=Range("B1"), Order1:=xlAscending
  9. End Sub
複製代碼

TOP

回復 7# lichang


    對了,如果你的office是2003的,那
    Range(Cells(1, 2), Cells(3, [XFD3].End(1).Column)).Select
    要改成
    Range(Cells(1, 2), Cells(3, [iv3].End(1).Column)).Select
    才不會超出範圍

TOP

回復 9# lichang


    sorry,改這樣應該就行了
  1. Private Sub CommandButton1_Click()
  2. Dim Col As Integer
  3. Col = Sheets("工作表1").[a1].End(xlToRight).Column + 1
  4. Cells(1, Col) = TextBox1.Value
  5. Cells(2, Col) = TextBox2.Value
  6. Cells(3, Col) = TextBox3.Value
  7. Range(Cells(1, 2), Cells(3, [iv3].End(1).Column)).Select
  8. Selection.Sort Key1:=Range("b1"), Order1:=xlAscending, Header:=xlGuess, _
  9.         OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, SortMethod _
  10.         :=xlStroke, DataOption1:=xlSortNormal
  11. End Sub
複製代碼

TOP

        靜思自在 : 【時間如鑽石】時間對一個有智慧的人而言,就如鑽石般珍貴;但對愚人來說,卻像是一把泥土,一點價值也沒有。
返回列表 上一主題