Easy fix to a current macros. Just need direction! Copy, Paste macro...

copleyr

Active Member
Joined
Aug 24, 2009
Messages
381
Hello,

The following is a macro that will go into a particular folder and pull the names of each excel file. (first characters of each file in the folder) It will list them in column "A" of a spreadsheet, It will space them out after every 16 rows.

The question is, how do I get the macro to paste the information in each row? It only does it after every 16 rows. Any help would be greatly appreciated. Thanks!

Code:
Sub ListFiles()
Dim MyPathName As String
Dim MyFileName As String
Dim NumChars As Long
Dim X As Long

    NumChars = 8
    MyPathName = "C:\Users\copleyr\Desktop\All/"
    MyFileName = Dir(MyPathName)
    Do While MyFileName <> ""
        X = X + 16
        Sheet1.Cells(X, 1) = Left(MyFileName, NumChars)
        MyFileName = Dir
    Loop
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try like this

Rich (BB code):
Sub ListFiles()
Dim MyPathName As String
Dim MyFileName As String
Dim NumChars As Long
Dim X As Long

    NumChars = 8
    MyPathName = "C:\Users\copleyr\Desktop\All/"
    MyFileName = Dir(MyPathName)
    Do While MyFileName <> ""
        X = X + 16
        Sheet1.Cells(X, 1).Resize(16).Value = Left(MyFileName, NumChars)
        MyFileName = Dir
    Loop
End Sub
 
Upvote 0
at the risk of sounding obvious, X = X + 1 instead of 16?

EDIT: ohhh, rigggght, now I get it ;)
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top