Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
Sub KKDP()
Dim totalrow As Integer
totalrow = Range("H6").Value
SaleIDLB = Range("J" & totalrow).Value
Do Until SaleIDLB = ""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"ODBC;DSN=SB MYOB 2009;", Destination:=Range("S3" & totalrow)).QueryTable
.CommandText = Array( _
"SELECT ItemSaleLines.TaxExclusiveTotal" & Chr(13) & "" & Chr(10) & "FROM ItemSaleLines ItemSaleLines" & Chr(13) & "" & Chr(10) & "WHERE (ItemSaleLines.SaleID=SaleIDDB) AND (ItemSaleLines.ItemID=77)" _
)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "KKDPLB"
.Refresh BackgroundQuery:=False
End With
Range("KKDPLB[[#Headers],[TaxExclusiveTotal]]").Select
ActiveSheet.ListObjects("KKDPLB").Unlist
Selection.ClearContents
Range("S" & totalrow).Select
Selection.Cut
Range("Q" & totalrow).Select
ActiveSheet.Paste
totalrow = totalrow + 1
SaleIDLB = Range("J" & totalrow).Value
Loop
End Sub
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Thank You