Macro
Macro
(OP)
Hey There
I am trying to make a macro but i met with a problem so i am looking for help
So plz have a look and help me out
CODE
Sub COPYpaste() Dim w1 As Workbook, w2 As Workbook, w3 As Workbook Set w1 = Workbooks.Open("C:\Users\Desktop\sample1.xls") Set w2 = Workbooks.Open("C:\Users\Desktop\sample2.csv") Set w3 = Workbooks.Open("C:\Users\Desktop\sample3.xlsx") Dim Ws1 As Worksheet, Ws2 As Worksheet, Ws3 As Worksheet Set Ws1 = w1.Worksheets.Item(1) Set Ws2 = w2.Worksheets.Item(1) Set Ws3 = w3.Worksheets.Item(1) Dim Lc3 As Long, Lenf1 As Long, Lr1 As Long Let Lr1 = Ws1.Range("A" & Ws1.Rows.Count & "").End(xlUp).Row Let Lc3 = Ws3.Cells.Item(1, Ws3.Columns.Count).End(xlToLeft).Column Dim Lc3Ltr As String Let Lc3Ltr = CL(Lc3) Let Lenf1 = Lr1 - 1 Dim rngOut As Range: Set rngOut = Ws2.Range("A1:" & Lc3Ltr & Lenf1 & "") Ws2.Cells.NumberFormat = "General" Let rngOut.Value = "='[sample3.xlsx]" & Ws3.Name & "'!A$1" Let rngOut.Value = rngOut.Value Let rngOut.Value = Evaluate("If({1},SUBSTITUTE(" & rngOut.Address & ", ""0"", """"))") Dim rngIn As Range Set rngIn = Ws3.Range("A1:" & Lc3Ltr & "1") rngIn.Copy rngOut.PasteSpecial Paste:=xlPasteValues w1.Close w2.Save Let Application.DisplayAlerts = False w2.Close Let Application.DisplayAlerts = True w3.Close End Sub
I am trying to make a macro but i met with a problem so i am looking for help
So plz have a look and help me out
RE: Macro
Could you add comments to each section of code, explaining what they are supposed to be doing?
Have you tried stepping through the code so you can see where it is going wrong?
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Macro
1.xls first row has headers so dont count that
In 1.xls count the total number of rows that has data and copy the 3.xlsx sheet3 first row(first complete row copy) and paste that much time of 3.xlsx first row of sheet3 to 2.csv
suppose 1.xls has data in 5 rows then copy 3.xlsx first row of sheet3 and paste it to 2.csv 5 times
i have attached a sample pic plz have a look
sample1.xls is 1.xls
sample2.csv is 2.csv
sample3.xlsx is 3.xlsx
RE: Macro
Instead of that i am geeting this after runing macro
RE: Macro
What is this line supposed to do?:
Let Lc3Ltr = CL(Lc3)
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Macro
Should be enough to get you going.
CODE --> VBA
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Macro
getting error with this line
RE: Macro
I am not a professional one
RE: Macro
But the code I posted is a new macro anyway. Did you try running it?
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Macro
i have three files 1.xls & 2.csv & 3.xlsx
In 1.xls first row has headers so dont count that
In 1.xls count the total number of rows that has data and copy the 3.xlsx sheet3 first row(first complete row copy) and paste that much time of 3.xlsx first row of sheet3 to 2.csv
suppose 1.xls has data in 5 rows then copy 3.xlsx first row of sheet3 and paste it to 2.csv 5 times
all files are located in a different path
sheet name can be anything
plz see the sample file
https://files.engineering.com/getfile.aspx?folder=...
https://files.engineering.com/getfile.aspx?folder=...
https://files.engineering.com/getfile.aspx?folder=...
RE: Macro
RE: Macro
Did you create two new worksheets for file sample1?
What were the values of Lc3Ltr and Lenf1 when you got the error message?
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Macro
CODE -->
I just googled and i saw the macro similar to this i modifed little things so thas y i am unable to provide u the exact details of my macro
and i ran ur macro Dis Sir which u modified and provided to me
RE: Macro
You need to read and understand the comments I added to your code.
To avoid the complications of using three files I created two new sheets, but if you are using your original file with just one sheet it won't work when it tries to write to sheet 2.
But if you don't understand what is going on with the original code I really think you would be better to start with something simpler anyway.
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Macro
We do not write code for novices. We will only give you Tips to improve your code.
We will not make a Macro for you. That's your job.
It is obvious that you are in deep water, way over your head and you don't know how to swim. We are not tutors.
Skip,
Just traded in my OLD subtlety...
for a NUance!
RE: Macro
I already have a conversation with ids
whatever he suggest & will provide i will accept that
But SkipVought I dont need ur tips and suggestions
RE: Macro
CODE -->
this code gives incorrect output dis sir plz see thes ample pic
RE: Macro
RE: Macro
Interestingly, you almost always have three files named 1, 2 & 3.
If any of you want proof that he's the same individual, you can reply to my FAQ766-2001: Make My Code Run Faster, with a brief message. Management will send me an eMail with your eMail address, and I'll send you my proof. Don't want to tip off this pretender.
Skip,
Just traded in my OLD subtlety...
for a NUance!
RE: Macro
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: Macro
TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm
RE: Macro
But this is my first time in engtips & i never ever registered and asked anything on tektips
RE: Macro
plz see this post
6 May 20 20:03
6 May 20 20:04
i mentioned the problem
this code is pasting the data incorrectly to 2.csv
RE: Macro
Its not the way I would do it, I'd read all the information into arrays, and write/process it to a VBA array with your final layout required. Then write the entire array back onto the sheet in one go. Copying and pasting things like you are doing shouldn't be required (really inefficient).
RE: Macro
plz see the pic that i have attached
RE: Macro
Skip,
Just traded in my OLD subtlety...
for a NUance!
RE: Macro
TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm