LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Weirdness

I have the following code which loops through values in the Column A and
uses the value from Column A in a Query that returns data from a database
and inserts the returned data to columns C and D.
(It also loops through all the sheets in the workbook)

After 8 rows, the population becomes a column insertion. If I limit the loop
to the first 8 rows, everything works fine. After 8 rows, I get new C and D
columns for every iteration of my loop.

Any help would be greatly appreciated.

Thanks






Sub GetInfo()

Dim strSqlString As String
Dim strConnString As String

Dim shtSheet As Worksheet
Dim lngX As Long

Dim rngCell As Range
Dim rngCol As Range
Dim intLastRow As Integer

For Each shtSheet In ActiveWorkbook.Sheets

Select Case MsgBox("Get info for the items listed on the " &
shtSheet.Name & " Sheet?", vbYesNoCancel, "Get Sheet Info?")
Case vbYes
shtSheet.Activate

'Determine Last Used Row and use for Selection Range
intLastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count

For lngX = 2 To intLastRow
DoEvents
If Trim(Range("B" & lngX).Text) < "" Then
'Query Database and return data to current row and
column D
strSqlString = "SELECT im.sales_pricing_unit as UOM,
il.standard_cost * im.sales_pricing_unit_size as COMM FROM inv_mast as im
(NOLOCK), inv_loc as il (NOLOCK) WHERE im.item_id = '" & Trim(Range("B" &
lngX).Text) & "' AND il.inv_mast_uid = im.inv_mast_uid"
strConnString = "ODBC;DSN=MyDSN;Database=MyDB"
With shtSheet.QueryTables.Add(Connection:=strConnString ,
_
Destination:=Range("C" & lngX),
Sql:=strSqlString)
.BackgroundQuery = False
.FieldNames = False
.Refresh
End With
End If
Next
Case vbCancel
Exit Sub
End Select

Next shtSheet

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arrow key weirdness Earl Kiosterud Excel Discussion (Misc queries) 3 April 7th 08 03:12 AM
Conditional Sum weirdness . . . WillRn Excel Worksheet Functions 1 February 17th 05 10:46 PM
VBA IDE Weirdness.... Trip[_2_] Excel Programming 3 June 17th 04 03:49 AM
Charting Weirdness and VBA Sandy V[_6_] Excel Programming 0 February 8th 04 11:19 AM
Charting Weirdness and VBA Markus Grein Excel Programming 0 February 7th 04 06:59 AM


All times are GMT +1. The time now is 07:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"