Peter Chan
asked on
Issue to copy details
Hi,
It is not copying full details of sheet through code below. Why?
https://1drv.ms/u/s!Ai8CrEskdewXu0c7aU5u35GZ2aA_?e=FOsiGq
It is not copying full details of sheet through code below. Why?
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = F2 Debug.Print F2 Application.DisplayAlerts = False Windows(Curr_Bk).Activate Worksheets(F2).Range("A2:D100").Copy wbk.Activate Worksheets(F2).Range("A2").PasteSpecial xlPasteValues wbk.Close SaveChanges:=True
When you run the file below, you can choose relevant Text file as the input. It will prompt for file when saving Excel file.https://1drv.ms/u/s!Ai8CrEskdewXu0c7aU5u35GZ2aA_?e=FOsiGq
ASKER
Good day Hainkurt,
Code below is not doing copy properly
Code below is not doing copy properly
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = Str0
Application.DisplayAlerts = False
Windows(Curr_Bk).Activate
Worksheets(Str0).Range("A1:D100").Copy
'Windows(W0).Activate
wbk.Activate
Worksheets(Str0).Range("A1").PasteSpecial xlPasteValues
'Workbooks(W0).Close SaveChanges:=True
wbk.Close SaveChanges:=True
What isn't being copied?
As it stand, your code is only copying values, in other words, formula results are kept, everything else is not (formatting, font, color ect ….).
Depend on what you want, you'll need to use another argument than xlPasteValue with the PasteSpecial function.
Side note:
Premature optimisation is the root of all evils.
Depend on what you want, you'll need to use another argument than xlPasteValue with the PasteSpecial function.
Side note:
Application.DisplayAlerts = False
Before using performances ehencing instructions, ensure that your code behave as expected.Premature optimisation is the root of all evils.
ASKER
Thanks to all.
You can run Excel file below
https://1drv.ms/x/s!Ai8CrEskdewXu0qyuwIP4nOs_Rnr?e=JgEhqr
by choosing relevant .txt file below,
https://1drv.ms/t/s!Ai8CrEskdewXu0sHFJDze7zj5GZ2?e=ZdjzzI
It is now having issue like
due to this line below.
You can run Excel file below
https://1drv.ms/x/s!Ai8CrEskdewXu0qyuwIP4nOs_Rnr?e=JgEhqr
by choosing relevant .txt file below,
https://1drv.ms/t/s!Ai8CrEskdewXu0sHFJDze7zj5GZ2?e=ZdjzzI
It is now having issue like
due to this line below.
Set wsForValidation = Worksheets(Par_Sht)
Previously there was no same issue. How to avoid it?
Peter
How do we select the text file?
How do we select the text file?
Worksheets(Par_Sht)
Par_Sht contains a string and there is no such sheet at that time...
simple as that... not sure where do you get/set that variables...
Par_Sht contains a string and there is no such sheet at that time...
simple as that... not sure where do you get/set that variables...
ASKER
Hi all,
Norie,
You can choose attached text file below, when saving Excel file.
3.txt
Hainkurt,
Par_sht is one Sheet name ending with "_C".
All,
For the code below, that is doing copy into another Excel file, it seems the followingA part does remove one sheet from "original" Excel file (wbk is actually new Excel file). How to correct it?
Norie,
You can choose attached text file below, when saving Excel file.
3.txt
Hainkurt,
Par_sht is one Sheet name ending with "_C".
All,
For the code below, that is doing copy into another Excel file, it seems the followingA part does remove one sheet from "original" Excel file (wbk is actually new Excel file). How to correct it?
wbk.Activate
Sh_Exist = False
Dim j As Integer
For j = 1 To Worksheets.Count
If Worksheets(j).Name = F2 Then
Sh_Exist = True
Exit For
End If
Next
If Sh_Exist Then
Application.DisplayAlerts = False
Sheets(F2).Delete
Application.DisplayAlerts = True
End If
Jeeeez, a worksheet completly build by code….
It will be better to have an hidden "master" worksheet that you will just duplicate.
Next, your functions are too long, and break the SRP (Single Responsibility Principle).
Write small functions that do one thing (and do it well).
When dealing with the file system, use the FSO object (it is in the Microsoft Scripting Runtime Library), it is more intuitive and safe.
Finally, what are you trying to achieve ?
With some luck, a Power BI solution will be more reliable, less head-breaking and easyer to maintain.
It will be better to have an hidden "master" worksheet that you will just duplicate.
Next, your functions are too long, and break the SRP (Single Responsibility Principle).
Write small functions that do one thing (and do it well).
When dealing with the file system, use the FSO object (it is in the Microsoft Scripting Runtime Library), it is more intuitive and safe.
Finally, what are you trying to achieve ?
With some luck, a Power BI solution will be more reliable, less head-breaking and easyer to maintain.
ASKER
Hi,
I checked that the part below is running for Child file but issue is that data is copied well to Child file. Any idea?
I checked that the part below is running for Child file but issue is that data is copied well to Child file. Any idea?
Sh_Exist = False
Dim j As Integer
For j = 1 To wbk.Worksheets.Count
If wbk.Worksheets(j).Name = F2 Then
Sh_Exist = True
Exit For
End If
Next
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
all on one line
+ zip attached have pw, which is not provided...