Results 1 to 1 of 1

Changing the number of rows when variable rows are returned by macro

Threaded View

intj.inc Changing the number of rows... 09-07-2012, 09:01 AM
  1. #1
    Registered User
    Join Date
    09-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Changing the number of rows when variable rows are returned by macro

    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.
    Last edited by Cutter; 09-08-2012 at 07:50 AM. Reason: Added code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1