1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

400 error on following

Discussion in 'Business Applications' started by dier02, Oct 27, 2011.

Thread Status:
Not open for further replies.
  1. dier02

    dier02 Thread Starter

    Joined:
    Oct 27, 2011
    Messages:
    2
    Public Sub ListWorkbooks()
    Dim Directory As String
    Dim FileName As String
    Dim IndexSheet As Worksheet
    Dim rw As Long

    Directory = "" & Range("Path").Value & ""
    If Left(Directory, 1) <> "\" Then
    Directory = Directory & "\"
    End If

    rw = 10

    Set IndexSheet = ThisWorkbook.ActiveSheet

    FileName = Dir(Directory & "*")
    Do While FileName <> ""

    IndexSheet.Cells(rw, 2).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!A3"
    IndexSheet.Cells(rw, 2).Copy
    IndexSheet.Cells(rw, 2).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 3).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!C1"
    IndexSheet.Cells(rw, 3).Copy
    IndexSheet.Cells(rw, 3).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 4).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!C2"
    IndexSheet.Cells(rw, 4).Copy
    IndexSheet.Cells(rw, 4).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 5).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!F53"
    IndexSheet.Cells(rw, 5).Copy
    IndexSheet.Cells(rw, 5).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 6).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!H53"
    IndexSheet.Cells(rw, 6).Copy
    IndexSheet.Cells(rw, 6).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 7).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!J53"
    IndexSheet.Cells(rw, 7).Copy
    IndexSheet.Cells(rw, 7).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 8).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!L53"
    IndexSheet.Cells(rw, 8).Copy
    IndexSheet.Cells(rw, 8).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 9).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!N53"
    IndexSheet.Cells(rw, 9).Copy
    IndexSheet.Cells(rw, 9).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 10).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!N53"
    IndexSheet.Cells(rw, 10).Copy
    IndexSheet.Cells(rw, 10).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 11).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!R53"
    IndexSheet.Cells(rw, 11).Copy
    IndexSheet.Cells(rw, 11).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 12).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!T53"
    IndexSheet.Cells(rw, 12).Copy
    IndexSheet.Cells(rw, 12).PasteSpecial Paste:=xlPasteValues

    IndexSheet.Cells(rw, 13).Formula = "='" & Directory & "[" & FileName & "]" & Range("SheetName").Value & "'!V53"
    IndexSheet.Cells(rw, 13).Copy
    IndexSheet.Cells(rw, 13).PasteSpecial Paste:=xlPasteValues

    rw = rw + 1
    FileName = Dir
    Loop

    Set IndexSheet = Nothing
    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    End Sub
     
  2. dier02

    dier02 Thread Starter

    Joined:
    Oct 27, 2011
    Messages:
    2
    To collate data in a number of excel files. There is one open sheet and one hidden sheet and it takes the data from the hidden sheet.
     
  3. Jimmy the Hand

    Jimmy the Hand

    Joined:
    Jul 28, 2006
    Messages:
    1,223
    Wrong:
    Code:
    If Left(Directory, 1) <> "\" Then
    Directory = Directory & "\"
    End If
    
    FileName = Dir
    
    Right:
    Code:
    If Right(Directory, 1) <> "\" Then
    Directory = Directory & "\"
    End If
    
    FileName = Dir()
    
    Jimmy
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1024320

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice