Hi Team,
I want to copy specific range of data from Sheet1 to another sheet.
With the help of ADODB and Record set and also not defining tables.
Below code works but it copy all data, unwanted data also.
I want to copy only range("D2:E5")
Below is a Actual Data
Thanks
mg
I want to copy specific range of data from Sheet1 to another sheet.
With the help of ADODB and Record set and also not defining tables.
Below code works but it copy all data, unwanted data also.
I want to copy only range("D2:E5")
VBA Code:
Option Explicit
Sub CopyDataNextPlace()
Dim Conn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Dim Sht As Worksheet
Dim FilePath As String, connstr As String
Dim ShtName As String
FilePath = ThisWorkbook.FullName
connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FilePath & _
";Extended Properties=""Excel 12.0 Macro;HDR=YES"";"
Conn.Open connstr
Set Sht = Sheets("Sheet1")
ShtName = Sht.Name
Rst.Open "[" & ShtName & "$]", Conn
Sheets.Add , Sht
Range("A1").CopyFromRecordset Rst
End Sub
Below is a Actual Data
State | City | |||
Maharashtra | Pune | State | City | |
Maharashtra | Mumbai | Maharashtra | Pune | |
Maharashtra | Nagpur | Gujarat | Surat | |
Gujarat | Ahmedabad | Karnataka | Bangalore | |
Gujarat | Surat | |||
Karnataka | Bangalore | |||
Thanks
mg