i am sending picture of my file and some code i am doing every thing through loop. it takes time approx 1 to 2 minute.
just i want to reduce the time with selection the ranges at once and changing the color.
when i started this project it takes time to complete same task 10 to 15 minute now it reduced only 1 to 2 minutes.
now i want to do when user select any option result should come with in seconds.
Yard.jpg
Sub X() 'Name Unknown, SamT
Dim Conn As New ADODB.Connection, StrSql As String
Dim rs As New ADODB.Recordset, rscn As New ADODB.Recordset, RSMix As New ADODB.Recordset
Dim DBpath As String, sconnect As String, TRec As Integer, ContCategory As String, DatStr As Variant
Dim StackRs As New ADODB.Recordset, StkSql As String, CelRng As Range, Qty As Integer, rng As Variant, IMx As Integer
Dim BlkBR As String, OutRt As String
Option Base 1
Sub MixedCnt()
'** if i declare it glogely it bring previously value
Dim TxtRotSer As String
Application.ScreenUpdating = False
Sheets("FilterData").Activate
Columns("A:A").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Sheets("Data").Activate
Rows("1:1").Select
Selection.Copy
Sheets("FilterData").Select
Rows("1:1").Select
ActiveSheet.Paste
Range("A1").Select
Call ClearBlk
Sheets("RotColor").Range("A1:A30").ClearContents
'FrmYard.LstRot.Selected(Item) = True
For i = 0 To FrmYard.LstRot.ListCount - 1
If FrmYard.LstRot.Selected(i) Then
AB = AB + 1
Sheets("RotColor").Range("A" & AB).Value = FrmYard.LstRot.List(i)
TxtRotSer = TxtRotSer & ",'" & FrmYard.LstRot.List(i) & "'"
End If
Next
If TxtRotSer = "" Then
Exit Sub
Else
TxtRotSer = Right(TxtRotSer, Len(TxtRotSer) - 1)
End If
If FrmYard.OPTRot = True Then
StrSql = "Select * from [DATA$A1:BN65000] WHERE len(BlockBayRow) > 3 and OutRotation in (" & TxtRotSer & ");"
ConnDbase
ElseIf FrmYard.OptServ = True Then
StrSql = "Select * from [DATA$A1:BN65000] WHERE len(BlockBayRow) > 3 and Vservice in (" & TxtRotSer & ");"
ConnDbase
End If
'ElseIf FrmYard.OptFLYard = True Then
'StrSql = "Select * from [DATA$A1:BN65000] WHERE AddedLoc <>'-' ;"
'End If
End Sub
Sub ConnDbase()
DBpath = ThisWorkbook.FullName
sconnect = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & DBpath & _
";Extended Properties=""Excel 12.0 XML; mACRO; HDR=Yes;"""
Conn.Open sconnect
rs.CursorLocation = adUseClient
rs.Open StrSql, Conn, adOpenStatic, adLockReadOnly
'*********** Make String
For Ary = 1 To rs.RecordCount
RecCnt = RecCnt + 1
Rcnt = RecCnt & " / " & rs.RecordCount
DatStr = DatStr & ",'" & rs.Fields(10) & "'"
rs.MoveNext
FrmYard.LblCnt.Caption = Rcnt
FrmYard.Repaint
Next Ary
If rs.RecordCount = 0 Then
MsgBox "No Record Found"
GoTo AB
End If
'**** Trim comma to make query accurate
DatStr = Right(DatStr, Len(DatStr) - 2)
DatStr = Left(DatStr, Len(DatStr) - 1)
'mixsql = "Select * from [DATA$A1:BN65000] WHERE Vservice in (" & TxtRotSer & ") and BlockBayRow in ('" & DatStr & "' );"
'**** this query is to capture other service or rotation mixed in one row
mixsql = "Select * from [DATA$A1:BN65000] WHERE BlockBayRow in ('" & DatStr & "' );"
RSMix.CursorLocation = adUseClient
RSMix.Open mixsql, Conn, adOpenDynamic, adLockOptimistic
RSMix.Sort = "[OutRotation]"
TRec = RSMix.RecordCount
Sheets("FilterData").Activate
Sheets("FilterData").Range("b1000000").End(xlUp).Select
Sheets("FilterData").Range("a1000000").End(xlUp).Offset(1, 0).CopyFromRecordset RSMix
DatStr = ""
'*****************************************
StkSql = "Select distinct BlockBayRow from [FilterData$A1:BN65000]"
StackRs.CursorLocation = adUseClient
StackRs.Open StkSql, Conn, adOpenDynamic, adLockReadOnly
Sheets(1).Activate
GroundSlot = StackRs.RecordCount
Do Until StackRs.EOF
'dtsql = "Select count(*) from [FilterData$A1:BN65000] where BlockBayRow ='" & StackRs.Fields(0).Value & "'"
BlkBR = StackRs.Fields(0).Value
Call StackMix
'Sheets("Blk").Range("a1000000").End(xlUp).Offset(1, 0).CopyFromRecordset StackRs1
StackRs.MoveNext
Loop
StackRs.Close
Set StackRs = Nothing
rs.Close
RSMix.Close
Conn.Close
AB:
Set rs = Nothing
Set RSMix = Nothing
Set Conn = Nothing
DatStr = ""
Application.ScreenUpdating = True
End Sub