將EXCEL一些列的值全部往上移

jho20186
我有個疑問疑問想請教各位神手,我EXCEL一些列的值須要往上移一列請問VBA該怎麼做??



roar
這是可以選一列或一個cell 後將資料向上提昇一列。
https://drive.google.com/file/d/13W1-m6MqjS2Qt1F-hN-OwA7UV807oNaS/view?usp=sharing

Option Explicit
Public rownumber As Integer

Private Sub CommandButton1_Click()

Dim Oldstr As String
Dim Newstr As String
Oldstr = CStr(rownumber) + ":" + CStr(rownumber)                    'Selected Row location
Newstr = CStr(rownumber - 1) + ":" + CStr(rownumber - 1)            'Destination Row locaiton
Rows(Oldstr).Select
Selection.Cut
Rows(Newstr).Select
ActiveSheet.Paste

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

rownumber = ActiveCell.Row

End Sub

Ann
假設妳希望A欄位="top"的列都上昇一列.
Sub test()
For i = 2 To 10

If Range("A" & i) = "top" And Range("A" & i - 1) <> "top" Then
Rows(i).Cut
Rows(i - 1).Insert
i = i - 1
End If

Next
End Sub
回到頂部