0

I have the code below and I need to import the data from a table in the range of "A:K".

Function ImportExport(ByVal template As String) As Boolean

    Dim Name As String
    Dim Code As String
    Dim table As String
    Dim Sheet As String
    
    If Dir(CurrentProject.Path & "\Folder1\*" & template & "*") = "" Then ImportExport = True
        Else
    Name = Dir(CurrentProject.Path & "\Folder1\*" & template & "*")
            
     Select Case template
                Case “Reality
                Code = “Try1”
                table = “secondTable"
                
                'Sheet = Sheets("Table_needs!”).Range("A:K")
                Sheet = "Table_needs!"

What I need is sth like it:

Sheet = Sheets("Table_needs!”).Range("A:K")

But it doesn't work in this structure. can anyone help?

Nathan_Sav
  • 8,466
  • 2
  • 13
  • 20
Flash
  • 85
  • 10
  • Is the ! in the tab name? Sheet is defined as string, not range. `Dim Sheet As Range` – Nathan_Sav Mar 01 '22 at 14:32
  • No, but anyway I tried with both "!" and without "!". but the result was the same – Flash Mar 01 '22 at 14:33
  • Tnx. but still when I concat Sheet = Sheets("Table_needs!”) and .Range("A:K")--> it shows me a coding error (the lines will be red) How can I write it correctly? Sheet = Sheets("Table_needs!”).Range("A:K") – Flash Mar 01 '22 at 14:40
  • What do you want the output `sheet` to be a string of the address of the range or the range? – Nathan_Sav Mar 01 '22 at 14:42
  • The VBA code was written by someone else and I need to change this part. What I need is to import data from a table sheet ONLY for the columns of A:K – Flash Mar 01 '22 at 14:53
  • 1
    It's difficult to fix that part without knowing what happens below the code you posted. Also you need to fix all those "smart" quotes in the code. – Tim Williams Mar 01 '22 at 17:07

0 Answers0