Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.
Sub sql_query() Application.ScreenUpdating = False Dim Code_Number As String Dim Color As String Dim usedRowCount Dim conn1 As New Connection Dim rec As New Recordset Dim comm As New Command Dim Str Set ws = ThisWorkbook.Worksheets("CDF Style Color") conn1.Open "Provider=MSDASQL;DRIVER=SQL SERVER;SERVER=192.168.1.1;111;DNS=DB;UID=SA;PWD=sa;DATABASE=db" Set comm.ActiveConnection = conn1 LR = Cells(Rows.Count, 1).End(xlUp).Row For i = 2 To 50 'LR ThisWorkbook.Sheets("CDF Style Color").Activate codenum = Cells(i, 1) clr = Cells(i, 2) Str = "Select code, color, upc, upc2, upc3, upc4, upc5, upc6, upc7, upc8, upc9, upc10, upc11, upc12, upc_prepack from ivtf where code ='" & codenum & "' and Color = '" & clr & "'" '& Chr(34) comm.CommandText = Str rec.Open comm Sheets("Style&Color_Match").Select Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).CopyFromRecordset rec rec.Close Next Rows(1).Delete Columns("A:AZ").Select Selection.Sort key1:=[C1], order1:=xlAscending, key2:=[A1], order2:=xlAscending, Header:=xlNo, MatchCase:=False, Orientation:=xlTopToBottom Application.DisplayAlerts = False Columns("A:A").Select Application.ScreenUpdating = True End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
|Increasing the value of a cell by 1 each time a macro is run||4||30|
|78 files, need to delete row 2 in every file||3||27|
|Create email hyperlinks from regular text||3||24|
|sort time order||10||38|
Join the community of 500,000 technology professionals and ask your questions.