|
|
- Sub Remove_Range()
- '
- ' Remove_Range Macro
- '
- '
- Application.Goto Reference:="Table_Query_from_SQL_Query"
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Selection.ListObject.ListColumns(1).Delete
- Range("B3").Select
- End Sub
- Sub SQL_Query_Demo()
- '
- ' Macro2 Macro
- '
- '
- Sheets.Add After:=Sheets(Sheets.Count)
- Range("B2").Select
- With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
- "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=acorntest;Use Procedure for Prepare=1;Auto T" _
- , _
- "ranslate=True;Packet Size=4096;Workstation ID=JZHANG-WIN7;Use Encryption for Data=False;Tag with column collation when possible=" _
- , "False;Initial Catalog=tmpData"), Destination:=Range("$B$2")).QueryTable
- .CommandType = xlCmdTable
- .CommandText = Array("""tmpData"".""dbo"".""branch""")
- .RowNumbers = False
- .FillAdjacentFormulas = False
- .PreserveFormatting = True
- .RefreshOnFileOpen = False
- .BackgroundQuery = True
- .RefreshStyle = xlInsertDeleteCells
- .SavePassword = False
- .SaveData = True
- .AdjustColumnWidth = True
- .RefreshPeriod = 0
- .PreserveColumnInfo = True
- .SourceConnectionFile = _
- "C:\Users\jzhang\Documents\My Data Sources\acorntest tmpData branch.odc"
- .ListObject.DisplayName = "Table_acorntest_tmpData_branch"
- .Refresh BackgroundQuery:=False
- End With
- Selection.AutoFilter
- Selection.ClearFormats
- ActiveSheet.ListObjects("Table_acorntest_tmpData_branch").TableStyle = ""
- Selection.ListObject.QueryTable.Delete
- End Sub
- Sub Macro3()
- '
- ' Macro3 Copy data from selected Range
- '
- '
- Application.Goto Reference:="Customer_Edit_Range"
- Selection.Copy
- Sheets("RecordControl").Select
- Range("A5").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Range("A5").Select
- End Sub
- Sub Macro4()
- '
- ' Macro4 Name a Range
- '
- '
- Sheets("RecordControl").Select
- Application.CutCopyMode = False
- ActiveWorkbook.Names.Add Name:="TestData", RefersToR1C1:= _
- "=RecordControl!R5C1:R6C13"
- Application.Goto Reference:="vDataRangeTL"
- Application.Goto Reference:="TestData"
- End Sub
- Sub Macro5()
- '
- ' Macro5 Copy, Paste and Rename the range
- '
- '
- Sheets("DataSource").Select
- Range("B3:G6").Select
- Selection.Copy
- Sheets("RecordControl").Select
- Range("A5").Select
- ActiveSheet.Paste
- Application.CutCopyMode = False
- ActiveWorkbook.Names.Add Name:="TestData", RefersToR1C1:= _
- "=RecordControl!R5C1:R8C6"
- Range("F19").Select
- Application.Goto Reference:="TestData"
- Selection.Delete Shift:=xlUp
- Range("A5").Select
- End Sub
- Sub Macro_copy()
- '
- ' Macro1 Macro
- ' Copy from one sheet in another workfile to another sheet Rename the Tag
- '
- '
- Windows("Book1").Activate
- Sheets("Sheet1").Name = "Source"
- Sheets("Sheet2").Name = "Dest"
- Application.CutCopyMode = False
- Sheets("Source").Range("B2").Copy
- Sheets("Dest").Select
- ActiveSheet.Paste Destination:=Worksheets("Dest").Range("A2")
- Sheets("Dest").Columns("A:A").EntireColumn.AutoFit
- Application.CutCopyMode = False
- Sheets("Source").Range("C2:N2").Copy
- Sheets("Dest").Paste Destination:=Sheets("Dest").Range("B2")
- 'Sheets("Dest").Range("B2").Select
- 'ActiveSheet.Paste
- Columns("B:B").EntireColumn.AutoFit
- Columns("C:C").EntireColumn.AutoFit
- Columns("D:D").EntireColumn.AutoFit
- Columns("M:M").EntireColumn.AutoFit
- Columns("L:L").EntireColumn.AutoFit
- Columns("K:K").EntireColumn.AutoFit
- Columns("J:J").EntireColumn.AutoFit
- Columns("I:I").EntireColumn.AutoFit
- Application.CutCopyMode = False
- Sheets("Source").Range("B3:B4").Copy
- 'Application.CutCopyMode = False
- 'Selection.Copy
- 'Sheets("Dest").Range("A3").Select
- Sheets("Dest").Paste Destination:=Sheets("Dest").Range("A3")
- 'Sheets("Source").Select
- 'Range("C3:N4").Select
- Application.CutCopyMode = False
- Sheets("Source").Range("C3:N4").Copy
- Sheets("Dest").Range("B3").Select
- Sheets("Dest").Paste Destination:=Sheets("Dest").Range("B3")
- Dim myList, myCell, i
- i = 1
- Sheets("Dest").Range("A3").Select
- 'myList = Sheets("Dest").Range(Selection.End(xlToLeft), Selection.End(xlToRight)).Select
- myList = Sheets("Dest").Range(Selection.End(xlUp), Selection.End(xlDown)).Select
- For Each myCell In Selection
- 'myCell.Value = "i"
- Windows("PERSONAL").Activate
-
- Sheets("Sheet1").Cells(i, 1).Value = myCell.Value
- Windows("Book1").Activate
- i = i + 1
- Next
- Sheets("Source").Select
- End Sub
- Sub Macro_Item_Process()
- '
- ' Micro to update report according to another reference list
- ' Copy data from one sheet in another another sheet and loop li to the end
- '
- '
- Dim i, j, op_Code, s_Cust, s_Cls, s_Alloy, s_Form, s_Date, s_Rep, s_Inv, s_Ton, s_Moh
- Windows("NV_Customer_Specific_Items").Activate
- Dim myList, myCell
- i = 1
- Sheets("Inv").Select
- Sheets("Inv").Range("B2").Select
- 'myList = Sheets("Dest").Range(Selection.End(xlToLeft), Selection.End(xlToRight)).Select
- myList = Sheets("Inv").Range("B2", Selection.End(xlDown)).Select
- For Each myCell In Selection
- s_Cust = myCell.Value: s_Cls = myCell.Offset(0, 1).Value: s_Alloy = myCell.Offset(0, 2).Value
- s_Form = myCell.Offset(0, 3).Value
- s_Date = myCell.Offset(0, 4).Value: s_Inv = myCell.Offset(0, 5).Value
- s_Ton = myCell.Offset(0, 6).Value
- Sheets("Detail").Select
- j = 2
- Do
-
- j = j + 1
- Loop While (j < 356) And (Sheets("Detail").Cells(j, 3).Value <> s_Cust Or _
- Sheets("Detail").Cells(j, 5).Value <> s_Cls Or Sheets("Detail").Cells(j, 6).Value <> s_Alloy Or _
- Sheets("Detail").Cells(j, 7).Value <> s_Form)
- If j > 355 Then
- op_Code = MsgBox("Customer: " + s_Cust + vbCrLf + "Class: " + s_Cls + vbCrLf + _
- "Alloy: " + s_Alloy + vbCrLf + "Form: " + s_Form + vbCrLf + "Continue ?", vbYesNo, "No Exist!")
- If op_Code = vbNo Then
- GoTo EndPro
- End If
- Else
- MsgBox "Line:" & j & " found the item: " & Sheets("Detail").Cells(j, 3).Value & " |" & _
- Sheets("Detail").Cells(j, 5).Value & "|Alloy:" & Sheets("Detail").Cells(j, 6).Value & "|Form:" & _
- Sheets("Detail").Cells(j, 7).Value & vbCrLf & _
- "Data into:" & vbCrLf & _
- "|" & s_Cust & "|" & s_Cls & "|" & s_Alloy & "|" & s_Form & _
- "|" & s_Date & "|" & s_Inv & "|" & s_Ton
- End If
-
- 'Sheets("Sheet1").Cells(i, 1).Value = myCell.Value
- Sheets("Inv").Select
- i = i + 1
- Next
- 'Sheets("Source").Select
- 'Windows("PERSONAL").Activate
- EndPro:
- End Sub
复制代码
|
|