Bit of a weird one here, I've got a macro which brings back data relating to one company or another, however each company has different amounts of data and therefore different number of rows in the report table. The problem I have is that the macro brings back data into another table below it, however due to the variable rows in the top table, the two tables either have large gaps between or they overlap making the report unusable. Is it possible to write some code so that the number of rows in the top table will change and correlate to the number of rows of data?
The macro I have so far is;
Sub UpdateQuery()
Dim cn As WorkbookConnection
Dim oledbCn As OLEDBConnection
Dim strOldBrokerName As String
Dim strNewBrokerName As String
Dim dteOld As String
Dim dteNew As String
strOldBrokerName = ThisWorkbook.Sheets("Control").Range("B2").Value
strNewBrokerName = InputBox(Prompt:="Enter the BrokerName?", Title:="BrokerName", Default:=strOldBrokerName)
dteOld = ThisWorkbook.Sheets("Control").Cells(1, 2).Value
dteOld = Format(dteOld, "YYYY-MM-DD")
dteNew = InputBox(Prompt:="Enter the 1st of the Report Period?", Title:="Report Date", Default:=dteOld)
dteNew = Format(dteNew, "YYYY-MM-DD")
With ThisWorkbook.Sheets("Control")
.Cells(1, 2).Value = dteNew
.Cells(2, 2).Value = strNewBrokerName
End With
For Each cn In ThisWorkbook.Connections
With cn.OLEDBConnection
Debug.Print strOldBrokerName, strNewBrokerName
.CommandText = Replace(.CommandText, "SET @BrokerName = '" & strOldBrokerName & "'", "SET @BrokerName = '" & strNewBrokerName & "'")
.CommandText = Replace(.CommandText, "SET @ReportDate = '" & dteOld & "'", "SET @ReportDate = '" & dteNew & "'")
.BackgroundQuery = False
.Refresh
End With
Next
End Sub
Is there any way to incorporate the modification of rows into this?
Thanks in advance :D
Moderator Edit:
Welcome to the forum, intj.inc
Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
Thanks.
Bookmarks