close

The way I have a macro setup right now I can import multiple text files
into one worksheet. THe problem is it stacks it on top of one another
going down two columns. I want to make a second macro that will take
these two columns and break it into multiple columns so that each file
has its own unique two columns to do analysis on.

The code I tried writing was simple and was

Range(quot;A177:B352quot;).Select
Selection.Cut
Range(quot;C1quot;).Select
Selection.Paste
Range(quot;A353:B528quot;).Select
Selection.Cut
Range(quot;E1quot;).Select
Selection.Paste
Range(quot;A529:B704quot;).Select
Selection.Cut
Range(quot;G1quot;).Select
Selection.Paste
Range(quot;A705:B880quot;).Select
Selection.Cut
Range(quot;I1quot;).Select

and so on and so forth to move 14 different files from two columns to
28 columns. I get an error message that says Object doesn't support
this property or method. Is there any easier way of doing this or am I
missing something in my code.

Thanks
BobSoe each text file is exactly 175 lines long?

If yes, you can try:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim oCol As Long
Dim iRow As Long
Dim myStep As Long

Set wks = Worksheets(quot;sheet1quot;)

myStep = 175
oCol = 1
With wks
For iRow = 177 To .Cells(.Rows.Count, quot;Aquot;).End(xlUp).Row Step myStep
oCol = oCol 2
.Cells(iRow, quot;Aquot;).Resize(myStep, 2).Cut _
Destination:=.Cells(1, oCol)
Next iRow
End With

End Sub

yanks6rule wrote:
gt;
gt; The way I have a macro setup right now I can import multiple text files
gt; into one worksheet. THe problem is it stacks it on top of one another
gt; going down two columns. I want to make a second macro that will take
gt; these two columns and break it into multiple columns so that each file
gt; has its own unique two columns to do analysis on.
gt;
gt; The code I tried writing was simple and was
gt;
gt; Range(quot;A177:B352quot;).Select
gt; Selection.Cut
gt; Range(quot;C1quot;).Select
gt; Selection.Paste
gt; Range(quot;A353:B528quot;).Select
gt; Selection.Cut
gt; Range(quot;E1quot;).Select
gt; Selection.Paste
gt; Range(quot;A529:B704quot;).Select
gt; Selection.Cut
gt; Range(quot;G1quot;).Select
gt; Selection.Paste
gt; Range(quot;A705:B880quot;).Select
gt; Selection.Cut
gt; Range(quot;I1quot;).Select
gt;
gt; and so on and so forth to move 14 different files from two columns to
gt; 28 columns. I get an error message that says Object doesn't support
gt; this property or method. Is there any easier way of doing this or am I
gt; missing something in my code.
gt;
gt; Thanks
gt; Bob

--

Dave Peterson

Hi Bob,
judging by the numbers in your code, each file is 176 lines long (352
-177 1 = 176), so in Dave's code just change quot;myStep = 175quot; quot;myStep =
176quot; and you should get the correct result if all files have the same
number of lines.
Ken JohnsonThat should have read quot;myStep = 175quot; to quot;myStep = 176quot;.
Ken JohnsonDarn arithmetic!

Thanks for the correction.

Ken Johnson wrote:
gt;
gt; That should have read quot;myStep = 175quot; to quot;myStep = 176quot;.
gt; Ken Johnson

--

Dave Peterson

You're welcome Dave.
Ken JohnsonSo do I just change the myStep to 176 or do I have to put in quot;myStep =
175quot; to quot;myStep = 176quot;So do I just change the myStep to 176 or do I have to put in quot;myStep =
175quot; to quot;myStep = 176quot;.

Thanks for all the help guys I am going to copy this and try it nowJust change this one line:
from:
myStep = 175
to

yanks6rule wrote:
gt;
gt; So do I just change the myStep to 176 or do I have to put in quot;myStep =
gt; 175quot; to quot;myStep = 176quot;.
gt;
gt; Thanks for all the help guys I am going to copy this and try it now

--

Dave Peterson

Just change this one line
from:
myStep = 175
to:
myStep = 176
yanks6rule wrote:
gt;
gt; So do I just change the myStep to 176 or do I have to put in quot;myStep =
gt; 175quot; to quot;myStep = 176quot;.
gt;
gt; Thanks for all the help guys I am going to copy this and try it now

--

Dave Peterson

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()