Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
VBA - Import range from other worksheet

I'm new to VBA and I'm trying to move my first steps into it, I need help!

Below you will find a code to import a range from a selected file to the active workbook. The macro is assigned to a button on the active workbook.

What I miss, and I'm not able to write is that I would like to paste the Range("U2:AH2") on the row of the active worksheet where the value of cell T2 (cell T2 is in the opened file) match a value in column D of the table in the active worksheet.

Sub Import_QTN_Data()

Dim FileToOpen As Variant
Dim OpenBook As Workbook

Application.ScreenUpdating = False

FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpen <> False Then
    Set OpenBook = Application.Workbooks.Open(FileToOpen)
    OpenBook.Worksheets("QUOTATION").Range("U2:AH2").Copy
    ThisWorkbook.Worksheets("QUOTATION").Range("E30").PasteSpecial xlPasteValues, skipblanks:=True

    OpenBook.Close False
End If

Application.ScreenUpdating = True

End Sub

Hope that somebody could help me in write this part of the code. Many thanks in advance

Luca

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You could use Match(), or Find(). Here's an example using Match()

Sub Import_QTN_Data()

    Dim FileToOpen As Variant
    Dim OpenBook As Workbook, wsQuote As Worksheet, m
    
    Application.ScreenUpdating = False
    
    FileToOpen = Application.GetOpenFilename( _
                  Title:="Browse for your File & Import Range", _
                  FileFilter:="Excel Files (*.xls*),*xls*")
    If FileToOpen <> False Then
        Set wsQuote = ThisWorkbook.Worksheets("QUOTATION")
        Set OpenBook = Application.Workbooks.Open(FileToOpen)
        With OpenBook.Worksheets("QUOTATION")
            'use Match() on ColD
            m = Application.Match(.Range("T2").Value, wsQuote.Columns("D"), 0)
            If Not IsError(m) Then       'got a match (`m` is not an error value)
                .Range("U2:AH2").Copy
                wsQuote.Cells(m, "E").PasteSpecial xlPasteValues, skipblanks:=True
            End If
        End With
        OpenBook.Close False
    End If
    
    Application.ScreenUpdating = True

End Sub
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda