这是个玩彩票的朋友要求做的。
我可以帮您试一下,请HI我.
回答者: lxlzmh2002 - 魔导师
十级 2009-8-31 23:31
=================================================================
再来更新此贴:
一. 移动程序代码:
Sub ToMove()
'this program is designed for cells moving by lxlzmh2002 on Sep
2,2009
Dim sht As Object
Dim rs As Long
Dim cs As Long
Dim i As Long
Dim rc As String
Dim mf As String
Dim mt As String
Dim rcs As Long
Dim os As Integer
Application.EnableEvents = False
Application.ScreenUpdating = False
'moving commands checking
os = 1
Sheets("order").Select
rs = Range("A65536").End(xlUp).Row
For i = 2 To rs
If InStr(1,
Cells(i, 1), ":") <> 0 Then
Cells(i, 1) = WorksheetFunction.Substitute(Cells(i, 1), ":",
":")
End If
If
(Left(Cells(i, 1), 1) = "r" Or Left(Cells(i, 1), 1) = "c") And
InStr(1, Cells(i, 1), ":") <> 0
Then
Else
MsgBox "注意: 第 " & i - 1 & "
行指令存在错误,请修正后再重试本程序!"
GoTo er
End If
If Not
WorksheetFunction.IsNumber(CInt(Trim(Mid(Cells(i, 1), InStr(1,
Cells(i, 1), ":") + 1, Len(Cells(i, 1)))))) Then
MsgBox "注意: 第 " & i - 1 & "
行指令中的移动到位置存在错误,请修正后再重试本程序!"
GoTo er
End If
Cells(i, 1)
= LCase(Left(Cells(i, 1), 1)) & Mid(Cells(i, 1), 2,
Len(Cells(i, 1)))
Next i
'create result sheet
On Error Resume Next
Set sht = Sheets("result")
If Err.Number = 0 Then
Sheets("result").Select
Sheets("result").Range("1:65536").ClearContents
Sheets("main").Range("1:"
&
Sheets("main").Range("A65536").End(xlUp).Row).Copy
Sheets("result").Range("A1")
Else
Sheets("main").Copy
after:=Sheets(Sheets.Count)
ActiveSheet.Name =
"result"
ActiveWorkbook.Sheets("result").Tab.ColorIndex = 44
End If
' to move
Sheets("result").Select
For i = 2 To rs
rc =
Left(Sheets("order").Cells(i, 1), 1)
mf =
Replace(Mid(Sheets("order").Cells(i, 1), 2, InStr(1,
Sheets("order").Cells(i, 1), ":") - 2), "-", ":")
If InStr(1,
mf, ":") = 0 Then
mf = CStr(CLng(mf) + os)
Else
mf = CStr(Left(mf, InStr(1, mf, ":") - 1) + os) &
":" & CStr(Mid(mf, InStr(1, mf, ":") + 1, Len(mf))
+ os)
End If
mt =
CStr(CLng(Trim(Mid(Sheets("order").Cells(i, 1), InStr(1,
Sheets("order").Cells(i, 1), ":") + 1, Len(Sheets("order").Cells(i,
1))))) + os)
Select Case
rc
Case
"r"
rcs = Rows(mf).Count
If Rows(mf).Row <= Rows(mt).Row Then
Range(CStr(CLng(mt) + rcs) & ":" &
CStr(CLng(mt) + 2 * rcs - 1)).EntireRow.Insert
Rows(mf).EntireRow.Copy Cells(CLng(mt) + rcs, 1)
Rows(mf).EntireRow.Delete
Else
Range(mt & ":" & CStr(CLng(mt) +
rcs - 1)).EntireRow.Insert
Range(CStr(Rows(mf).Row + rcs) & ":"
& CStr(Rows(mf).Row + 2 * rcs - 1)).EntireRow.Copy
Cells(mt, 1)
Range(CStr(Rows(mf).Row + rcs) & ":"
& CStr(Rows(mf).Row + 2 * rcs -
1)).EntireRow.Delete
End If
Case
"c"
If InStr(1, mf, ":") = 0 Then
mf = cn(CLng(mf))
Else
mf = cn(CLng(Left(mf, InStr(1, mf, ":") - 1))) &
":" & cn(CLng(Mid(mf, InStr(1, mf, ":") + 1,
Len(mf))))