Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format Problems using Copy/Paste with QueryTable

The following code is part of an Excel 2000 VBA module.

The routine Copy_And_Query is called to copy the format template in the Range(A1:AH50)

The Cell(C61:Hxx) values are magically obtained from the Query function where xx is = RecordCount + 60 of the SQL selection.

All of this works great except for the fact that Row 61 always loses the format properties obtained from Row11, while Rows 62 through 100 remain like rows 12 through 50 regardless of the Row count returned from the SQL selection.

Queue Paso????

Regards,
Hudel


Thanks you much if you have any understanding of this.


Sub Copy_And_Query()

Dim lCnt as Long
Dim xSheet as Excel.WorkSheet
Dim xBook as Excel.WorkBook
Dim sSql as String
Dim sCopyTo as String
Dim sCopyFrom as String

Set xBook = ActiveWorkBook
Set xSheet = .Sheets(Report)

sCopyTo = "A51"
sCopyFrom = "A1:AH50"

With xSheet
..Range(sRefer).Copy
..Range(sCopyTo).PasteSpecial xlPasteAll
End With xSheet

SSql = Select Col3, Col4, Col5, Col6, Col7, Col8 _
& From My_Table _
& Where Col1=Y and Col210

LCnt = Query_Run(xSheet, sSql, C11)

End Sub

Function Query_Run _
(xSheet As Excel.Worksheet, _
sSql As String, _
sRange As String) _
As Long
Dim rsQuery As ADODB.Recordset
Dim qt As QueryTable

On Error GoTo Query_Run_Error

With xSheet

Set rsQuery = Get_Rs(sSql, Query_Run) Get AdoDB RecortSet _
where Query_Run is set to the Record Count

Set qt = .QueryTables.Add(rsQuery, .Range(sRange))

With qt
..Name = "PathWAI Import"
..FieldNames = False
..RowNumbers = False
..FillAdjacentFormulas = False
..PreserveFormatting = True
..RefreshOnFileOpen = False
..BackgroundQuery = True
..RefreshStyle = xlOverwriteCells
..SavePassword = False
..SaveData = True
..AdjustColumnWidth = False
..RefreshPeriod = 0
..WebFormatting = xlWebFormattingAll
..WebPreFormattedTextToColumns = True
..WebConsecutiveDelimitersAsOne = True
..WebSingleBlockTextImport = False
..WebDisableDateRecognition = False
..Refresh BackgroundQuery:=False
End With 'qt
End With
Exit Function

Query_Run_Error:
vX = Err.Description
Resume Next
End Function

Reply
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
Two Problems Re Copy & Paste Robert11 New Users to Excel 1 February 13th 08 02:15 PM
Copy/Paste of QueryTable doesn't adjust relative parameters btait1 Excel Discussion (Misc queries) 1 September 30th 05 06:51 PM
Copy - Paste problems Guillermo Excel Discussion (Misc queries) 0 April 9th 05 04:27 AM
Using Copy/Paste and QueryTable Operations Hudel Holmes Excel Programming 0 November 17th 03 04:52 PM
Using VBA Copy/Paste and QueryTable Hudel H Excel Programming 0 November 17th 03 04:41 PM


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

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

About Us

"It's about Microsoft Excel"