Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7810753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:54:20+00:00 2026-06-02T03:54:20+00:00

Following is the VBA code to fetch data from oracle database to excel. Instead

  • 0

Following is the VBA code to fetch data from oracle database to excel.
Instead of the data going to some random sheet I want the data related to collabname 301_CBCompanySync_SAP_to_HHT to be gone into a sheet named 301_CBCompanySync_SAP_to_HHT and the

data related to the collabname 302_CBCustomer_SAP_to_HHT to be gone into sheet named “302_CBCustomer_SAP_to_HHT” ..so on

How shall I modify the below code

 Sub Load_data()

        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim col As Integer
        Dim row As Integer
        Dim Query As String
        Dim mtxData As Variant


        Set cn = New ADODB.Connection
        Set rs = New ADODB.Recordset

     cn.Open ( _
    "User ID=xxxx" & _
    ";Password=xxxxx" & _
    ";Data Source=xx.xx.xx.xxx:xxxx/xxxxxx" & _
    ";Provider=OraOLEDB.Oracle")


Dim arrayCollabName As Variant
Dim idx As Integer
idx = 0
arrayCollabName = Array("301_CBCompanySync_SAP_to_HHT", "302_CBCustomer_SAP_to_HHT", "303_CustomerExclusionList_SAP_to_HHT")


  For idx = 0 To 2

    Sheets("Sheet1").Select
    Sheets.Add

    rs.Open "select COLLABNAME,DATETIME,TOTALFLOWS,SUCCFLOWS,FAILEDFLOWS from EWS_COLLAB WHERE COLLABNAME like '" & arrayCollabName(idx) & "'", cn


        col = 0
        Do While col < rs.Fields.Count
            .Cells(1, col + 1) = rs.Fields(col).Name
            col = col + 1
        Loop
        mtxData = Application.Transpose(rs.GetRows)
        .Range("A2").Resize(UBound(mtxData, 1) - LBound(mtxData, 1) + 1, UBound(mtxData, 2) - LBound(mtxData, 2) + 1) = mtxData

    End With
    rs.Close

  Next

cn.Close
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:54:23+00:00Added an answer on June 2, 2026 at 3:54 am

    so, hope its ok.

    Sub Load_data()
        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim col As Integer
        Dim row As Integer
        Dim Query As String
        Dim mtxData As Variant
        Dim arrayCollabName As Variant
        Dim idx As Integer
    
    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    idx = 0
    'array with all collab names
    arrayCollabName = Array("301_CBCompanySync_SAP_to_HHT", "302_CBCustomer_SAP_to_HHT", "303_CustomerExclusionList_SAP_to_HHT")
    
    'connect to Database
     cn.Open ( _
    "User ID=xxxx" & _
    ";Password=xxxxx" & _
    ";Data Source=xx.xx.xx.xxx:xxxx/xxxxxx" & _
    ";Provider=OraOLEDB.Oracle")
    
    'loop for inserting the Data from the SQL
    For idx = 0 To 2
        Sheets("Sheet1").Select
        Sheets.Add
        'Rename the new added sheet
        If Len(arrayCollabName(idx)) > 31 Then
            ActiveSheet.Name = Left(arrayCollabName(idx), 31)
        Else
            ActiveSheet.Name = arrayCollabName(idx)
        End If
        'database query
        rs.Open "select COLLABNAME,DATETIME,TOTALFLOWS,SUCCFLOWS,FAILEDFLOWS from EWS_COLLAB WHERE COLLABNAME like '" & arrayCollabName(idx) & "'", cn
    
    
        col = 0
        Do While col < rs.Fields.Count
            .Cells(1, col + 1) = rs.Fields(col).Name
            col = col + 1
        Loop
        mtxData = Application.Transpose(rs.GetRows)
        .Range("A2").Resize(UBound(mtxData, 1) - LBound(mtxData, 1) + 1, UBound(mtxData, 2) - LBound(mtxData, 2) + 1) = mtxData
    
        End With
        'database query with the search results closing
        rs.Close
    Next
    'database connection closed
    cn.Close
    End Sub
    
        Sub deletSheets()
            Dim idx As Integer
            Application.DisplayAlerts = False
            For idx = 0 To ActiveWorkbook.Sheets.Count
                If Not ActiveSheet.Name = "Sheet1" Then
                    ActiveWindow.SelectedSheets.Delete
                End If
            Next idx
            Application.DisplayAlerts = True
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to put the following code into VBA. What I ideally want
Win-XP / Excel 2003 / VBA .... I have the following piece of code
I have some VBA code in an Excel workbook. I have a cell which
I have the following VBA code: mainFile = ActiveWorkbook.Name 'select all excel files in
I have the following VBA code inside an Excel macro: With ActiveSheet.QueryTables.Add( _ Connection:=ConnStr,
In Excel 2007 I have the following very simple code in VBA: Public Type
The following VBA code (Excel 2007) is failing with Error 1004, Autofill Method of
I want to do the moral equivalent of the following VBA code: For Each
Hey fellas, I have the following VBA code. It gets the values from an
I have the following VBA code within excel. It's goal is to remove a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.