Consulting

Results 1 to 4 of 4

Thread: Macro to copy excel recordset and insert in to Database based on a condition

  1. #1
    VBAX Regular
    Joined
    Jan 2008
    Posts
    15
    Location

    Macro to copy excel recordset and insert in to Database based on a condition

    In Column "U" i have values "Y" or "N"
    E.g. If U2 cell value is "Y" it should copy the whole row range A2:T2 recordset and insert the values in to a table in database &
    should loop it till the end of the data. I would greatly Appreciate and welcome VBA experts advise in this regards.

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    
    Sub test()
        Dim wsS As Worksheet
        Dim wsD As Worksheet
        
        Set wsS = Sheets("Source")
        Set wsD = Sheets("Databese")
        
        With wsS.Range("U1", wsS.Range("U" & Rows.Count).End(xlUp))
            .AutoFilter
            .AutoFilter 1, "Y"
            If .SpecialCells(xlCellTypeVisible).Count > 1 Then
                .Offset(1).EntireRow.Columns("A:T").Copy _
                    wsD.Range("A" & Rows.Count).End(xlUp).Offset(1)
            End If
            .AutoFilter
        End With
        
        wsD.Activate
        
    End Sub

  3. #3
    VBAX Regular
    Joined
    Jan 2008
    Posts
    15
    Location
    Hi Mana,

    Many thanks for the reply.
    But database is not a worksheet. I meant copy the source worksheet data to oracle database table. How should i use insert into SQL query in the code to copy the above filtered data.
    Thanks in Advance

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sorry. Please wait for the answers of other respondents.

Tags for this Thread

Posting Permissions

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