標題:
[發問]
複製儲存格範圍
[打印本頁]
作者:
caichen3
時間:
2012-5-11 14:51
標題:
複製儲存格範圍
請教大大
希望按下"確定"後將sheet1.range("E1:N2").value複製於sheet2.range("E3:N4")
以下是我的程式碼
Private Sub CommandButton8_Click()
Dim b As Integer
Dim k As Integer
Dim c As Integer
Dim d As Integer
henji = MsgBox("確定輸入 " & Range("A1").Value & "個製程需求?", Buttons:=vbYesNo + vbQuestion, Title:="需求數確認")
b = Range("A2").Value
k = Sheet2.Range("A5").Value
If (henji = 6) Then
c = b
If b > k Then
b = b - k
For i = 1 To b
Sheet2.Columns("F").Insert
Next
ElseIf b < k Then
b = k - b
For i = 1 To b
Sheet2.Columns("F").Delete
Next
End If
Sheet2.Range("A5").Value = c
d = 4 + b
Range(Cells(1, 5), Cells(2, d)).Copy Sheet2.Range("E3")
End If
End Sub
文色字體程式在新增一行後會出問題,請求大大幫忙看看哪裡出錯了??
作者:
f3202
時間:
2012-5-11 19:05
是因Sheet2.Range("E3")的格式吧
作者:
caichen3
時間:
2012-5-11 23:54
.Copy的用法能將儲存格合併嗎??
作者:
register313
時間:
2012-5-12 16:52
回復
3#
caichen3
簡化一下程式
Private Sub CommandButton8_Click()
With Sheet2
LC = .[IV3].End(xlToLeft).Column
If LC > 7 Then .Range(.Cells(3, 5), .Cells(4, LC - 3)).Delete Shift:=xlToLeft
End With
With Sheet1
LC = .[IV2].End(xlToLeft).Column
.Range(.Cells(1, 5), .Cells(2, LC)).Copy
Sheet2.Range("E3:E4").Insert Shift:=xlToRight
End With
End Sub
複製代碼
作者:
hugh0620
時間:
2012-5-16 11:12
回復
3#
caichen3
問題在 b = Range("A2").Value
若Range("A2").Value =""或是0時~ 您執行的時候就會錯誤
henji = MsgBox("確定輸入 " & Range("A1").Value & "個製程需求?", Buttons:=vbYesNo + vbQuestion, Title:="需求數確認")
b = Range("A2").Value
這兩行調一下位置~ 如下
b = Range("A2").Value
IF b<0 THEN
MsgBox "請重新確定您的製程需求數"
Exit Sub
ELSE
henji = MsgBox("確定輸入 " & Range("A1").Value & "個製程需求?", Buttons:=vbYesNo + vbQuestion, Title:="需求數確認")
END IF
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)