Option Explicit
Dim Flag
Dim myRow As Integer
--------------------------------
Sub addsheet()
Sheets.Add
Sheets(1).Select
ActiveSheet.Name = "pick"
End Sub
---------------------------------
Sub Choose(k)
If Worksheets("Sheet1").Cells(k, 5).Value > 10 Then
Flag = 1
ElseIf Worksheets("Sheet1").Cells(k, 5).Value > 5 And Worksheets("Sheet1").Cells(k, 5).Value <= 10 Then
Flag = 0
End If
End Sub
----------------------------------
Sub CopyPaste(L, M)
Dim myStr As String
myStr = L & ":" & L
Rows("20:20").Select
Selection.Copy
Sheets("pick").Select
' myStr = a & ":" & "M"
Range(myStr).Select
ActiveSheet.Paste
End Sub
---------------------------------
Sub main2()
Dim i As Integer
Dim myRange As Range
Dim myCell
Set myRange = Application.InputBox("Choose the days", Type:=8) '幫我選取我要的東西
For Each myCell In myRange '在我的myrange裡對每一個mycell,來做下面的事情
i = myCell.Row
Flag = 0 '不符合我的要求就跳到下一圈去看是否有符合
Choose i '檢測第20行是否符合我設的條件
If Flag = 1 Then
CopyPaste i, myRow '符合設定條件,貼到新的工作表,因為不是只有第二十行,所以要寫迴圈
myRow = myRow + 1
End If
Next
End Sub作者: Hsieh 時間: 2012-2-26 18:57
Sub ChooseVer2(rowChoose, sheetName As String) '原先只有輸入列號,現在要加上工作表的名字
If Worksheets("sheetName").Cells(rowChoose, 5).Value > 10 Then
Flag = 1 '只選取指定sheet的資料做篩選
Else
End If
End Sub
Sub CopyPasteVer2(rowCopy, rowPaste, copySheet As String, pasteSheet As String) 'copy the row rowcopy in sheet with name "2330"
Dim myStr As String 'and paste to the row rowpaste in the sheet "pick"
For Each myCell In myRange '在我的myrange裡對每一個mycell,來做下面的事情
i = myCell.Row
Flag = 0 '不符合我的要求就跳到下一圈去看是否有符合
ChooseVer2 i, mySheet '檢測第20行是否符合我設的條件
If Flag = 1 Then
CopyPasteVer2 i, myRow, mySheet, newSheet '符合設定條件,貼到新的工作表,因為不是只有第二十行,所以要寫迴圈
myRow = myRow + 1
End If
程式碼如下:
--------------------------------
Option Explicit
Dim Flag
Dim myRow As Integer
Dim newSheet As String
---------------------------------
Sub addsheetVer2()
Static Num As Integer
Num = Num + 1
End Sub
----------------------------------------------
Sub ChooseVer2(rowChoose, sheetName As String) '原先只有輸入列號,現在要加上工作表的名字
If Worksheets("sheetName").Cells(rowChoose, 5).Value > 10 Then
Flag = 1 '只選取指定sheet的資料做篩選
Else: the Flag = 0
End If
End Sub
-----------------------------------------
Sub CopyPasteVer2(rowCopy, rowPaste, copySheet As String, pasteSheet As String) 'copy the row rowcopy in sheet with name "2330"
Dim myStr As String 'and paste to the row rowpaste in the sheet "pick"
End Sub
-------------------------------------------
Sub main4()
Dim i As Integer
Dim mySheet As String
mySheet = InputBox("input the sheet name you analyze") '選擇工作表
addsheetVer2 '執行上述新增工作表的程式,每次增加的不一樣,可以執行上面寫的好幾個副程式,可以讓每個程式分工合作,組合在一起
myRow = 1: i = 2
Do While Worksheets(mySheet).Cells(i, 1) <> "" '在指定的工作表裡第一行往下掃只要不是空白格就執行下面的程式碼
Flag = 0 '不符合我的要求就跳到下一圈去看是否有符合
ChooseVer2 i, mySheet '檢測是否符合我設的條件
If Flag = 1 Then
CopyPasteVer2 i, myRow, mySheet, newSheet '符合設定條件,貼到新的工作表,因為不是只有第二十行,所以要寫迴圈
myRow = myRow + 1
End If
i = i + 1
Loop
End Sub作者: yagami12th 時間: 2012-2-26 22:18
Sub ChooseVer2(rowChoose, sheetName As String) '原先只有輸入列號,現在要加上工作表的名字
If Worksheets(sheetName).Cells(rowChoose, 5).Value > 10 Then
Flag = 1 '只選取指定sheet的資料做篩選
End If
End Sub
Sub CopyPasteVer2(rowCopy, rowPaste, copySheet As String, pasteSheet As String) 'copy the row rowcopy in sheet with name "2330"
Dim myStr As String 'and paste to the row rowpaste in the sheet "pick"
For Each myCell In myRange '在我的myrange裡對每一個mycell,來做下面的事情
i = myCell.Row
Flag = 0 '不符合我的要求就跳到下一圈去看是否有符合
ChooseVer2 i, mySheet '檢測第20行是否符合我設的條件
If Flag = 1 Then
CopyPasteVer2 i, myRow, mySheet, newSheet '符合設定條件,貼到新的工作表,因為不是只有第二十行,所以要寫迴圈
myRow = myRow + 1
End If
Next
End Sub
Sub main4()
Dim i As Integer
Dim mySheet As String
mySheet = InputBox("input the sheet name you analyze") '選擇工作表
addsheetVer2 '執行上述新增工作表的程式,每次增加的不一樣,可以執行上面寫的好幾個副程式,可以讓每個程式分工合作,組合在一起
myRow = 1: i = 2
Do While Worksheets(mySheet).Cells(i, 1) <> "" '在指定的工作表裡第一行往下掃只要不是空白格就執行下面的程式碼
Flag = 0 '不符合我的要求就跳到下一圈去看是否有符合
ChooseVer2 i, mySheet '檢測是否符合我設的條件
If Flag = 1 Then
CopyPasteVer2 i, myRow, mySheet, newSheet '符合設定條件,貼到新的工作表,因為不是只有第二十行,所以要寫迴圈
myRow = myRow + 1
End If
i = i + 1
Loop
End Sub作者: yagami12th 時間: 2012-2-26 22:49
Num = Num + 1
End Sub
----------------------------------------------------------------
Sub ChooseVer2(rowChoose, sheetName As String) '原先只有輸入列號,現在要加上工作表的名字
If Worksheets(sheetName).Cells(rowChoose, 5).Value > 10 Then
Flag = 1 '只選取指定sheet的資料做篩選
End If
End Sub
-------------------------------------------------------------------
Sub CopyPasteVer2(rowCopy, rowPaste, copySheet As String, pasteSheet As String) 'copy the row rowcopy in sheet with name "2330"
Dim myStr As String 'and paste to the row rowpaste in the sheet "pick"
End Sub
--------------------------------------------------------------------
Sub main3()
Dim i As Integer
Dim myRange As Range
Dim myCell
Dim mySheet As String
mySheet = InputBox("input the sheet name you analyze") '選擇工作表
Set myRange = Application.InputBox("Choose the days", Type:=8) '幫我選取我要篩選的範圍
For Each myCell In myRange '在我的myrange裡對每一個mycell,來做下面的事情
i = myCell.Row
Flag = 0 '不符合我的要求就跳到下一圈去看是否有符合
ChooseVer2 i, mySheet '
If Flag = 1 Then
CopyPasteVer2 i, myRow, mySheet, newSheet '在指定的工作表作篩選後貼過去,符合設定條件,貼到新的工作表,因為不是只有第二十行,所以要寫迴圈
myRow = myRow + 1
End If
Num = Num + 1
End Sub
----------------------------------------------------------------
Sub ChooseVer2(rowChoose, sheetName As String) '原先只有輸入列號,現在要加上工作表的名字
If Worksheets(sheetName).Cells(rowChoose, 5).Value > 10 Then
Flag = 1 '只選取指定sheet的資料做篩選
End If
End Sub
-------------------------------------------------------------------
Sub CopyPasteVer2(rowCopy, rowPaste, copySheet As String, pasteSheet As String) 'copy the row rowcopy in sheet with name "2330"
Dim myStr As String 'and paste to the row rowpaste in the sheet "pick"