View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary West Gary West is offline
external usenet poster
 
Posts: 5
Default Excel query creates named range

Thanks, Dick. The data in the spreadsheet isn't updated in place.
Each time the query is run, it's being used to pull down new and
different client info. The macro inserts the new info at the next
blank line based on a certain column that will always contain data.
The spreadsheet is being used to track contact with clients (the
"clients" are internal to the company).

I created the query and then recorded a macro that used it. Here's
the VBA

With ActiveSheet.QueryTables.Add(Connection:= _
"FINDER;C:\pathtoqueries\ClientTracking4.dqy" _
, Destination:=Cells(Rows.Count, "B").End(xlUp).Offset(1, 0))
.Name = "ClientTracking"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With

Someone helped out in this group with placing the cursor in the next
empty cell in column B. The query prompts for a number to be entered.

Are you saying that I can place the cursor and then use the Refresh
method to get new data without creating a new named range?

Thanks.

gary

"Dick Kusleika" wrote in
:

Gary

You probably don't need to create a new QueryTable every time. Create
the QueryTable once then use

Sheet1.QueryTables(1).Refresh

to update the data. If you need to change the QT every time, you can
do that also without deleting and recreating it.