peterhess2002
New Member
- Joined
- Mar 29, 2024
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hello!
I have a file called fileX.dat, which I conneted with a query in a sheet.
The file look like this:
And I have a sheet called sheet_X, which has a query predefined and called: sample_query
Now I want to use the items in fileX.dat (data1.dat, xyz.dat & abc.dat) to create three sheets as a copy from sheet_X with its query
I was able to do that using the vba_code:
---------------------
Sub Test_1()
Dim i As Long
Dim LastFileNum As Long
Dim Name As String
Sheets("FileX").Activate
New_Position = 0
For i = 1 To 3
Actual_Name = Sheets("FileX").Cells(i, 1)
Length_Name = Len(Actual_Name)
Length_Name_New = Length_Name - 4
Actual_Name_New = Left(Actual_Name, Length_Name_New)
New_Position = New_Position + 1
Sheets("sheet_X").Copy After:=Sheets(New_Position)
ActiveSheet.Name = Actual_Name_New
Sheets(Actual_Name_New).Activate
Next i
End Sub
--------------------------------
The code works fine and generates for me the three sheets with the queries.
The problem that I am facing is that the name of the new queries generated are copies of the original name of the query + (2) and + (3)
I want to rename the new generated queries to be as Actual_Name_New.
Any Idea?
Regards
Peter
I have a file called fileX.dat, which I conneted with a query in a sheet.
The file look like this:
data1.dat |
xyz.dat |
abc.dat |
And I have a sheet called sheet_X, which has a query predefined and called: sample_query
Now I want to use the items in fileX.dat (data1.dat, xyz.dat & abc.dat) to create three sheets as a copy from sheet_X with its query
I was able to do that using the vba_code:
---------------------
Sub Test_1()
Dim i As Long
Dim LastFileNum As Long
Dim Name As String
Sheets("FileX").Activate
New_Position = 0
For i = 1 To 3
Actual_Name = Sheets("FileX").Cells(i, 1)
Length_Name = Len(Actual_Name)
Length_Name_New = Length_Name - 4
Actual_Name_New = Left(Actual_Name, Length_Name_New)
New_Position = New_Position + 1
Sheets("sheet_X").Copy After:=Sheets(New_Position)
ActiveSheet.Name = Actual_Name_New
Sheets(Actual_Name_New).Activate
Next i
End Sub
--------------------------------
The code works fine and generates for me the three sheets with the queries.
The problem that I am facing is that the name of the new queries generated are copies of the original name of the query + (2) and + (3)
I want to rename the new generated queries to be as Actual_Name_New.
Any Idea?
Regards
Peter