在最后一个单元格中添加表中的新行

时间:2015-08-27 05:12:34

标签: excel-vba vba excel

我正在使用此代码。我需要为DY1到Dy30这样做。这将是很多代码而且非常冗长。如何使它紧凑而短小?

另外,我想在执行最后一个IF语句时在Active Sheet中向表中添加新行。

Option Explicit
Sub send()

Dim val As String
Dim j As Integer

val = Sheets("Form").Range("C8").Value

'-------FORDY1-----------

If val = "DY1" Then
For j = 2 To 9

Sheets("Form").Cells(j, 3).Copy

If j = 2 Then
Sheets("1").Select
Range("A" & Cells.Rows.Count).End(xlUp).Select
ActiveSheet.Paste
Else

If j = 3 Then
Sheets("1").Select
Range("B" & Cells.Rows.Count).End(xlUp).Select
ActiveSheet.Paste
Else

If j = 4 Then
Sheets("1").Select
Range("C" & Cells.Rows.Count).End(xlUp).Select
ActiveSheet.Paste
Else

If j = 5 Then
Sheets("1").Select
Range("D" & Cells.Rows.Count).End(xlUp).Select
ActiveSheet.Paste
Else

If j = 6 Then
Sheets("1").Select
Range("E" & Cells.Rows.Count).End(xlUp).Select
ActiveSheet.Paste
Else

If j = 7 Then
Sheets("1").Select
Range("F" & Cells.Rows.Count).End(xlUp).Select
ActiveSheet.Paste
Else

If j = 8 Then
Sheets("1").Select
Range("G" & Cells.Rows.Count).End(xlUp).Select
ActiveSheet.Paste
Else

If j = 9 Then
Sheets("1").Select
Range("H" & Cells.Rows.Count).End(xlUp).Select
ActiveSheet.Paste
Table.ListRows.Add 'Trying to add new row or send "Tab" key which normally get's down on next row of table
Else
End If
End If
End If
End If
End If
End If
End If
End If
Next j
Else
End If

End Sub

0 个答案:

没有答案