我做了一个宏来搜索和选择电子表格中的数据。基本上,当它找到数据时,它会选择该单元格。现在我希望能够在不同的Excel工作簿中将该单元格和更多单元格复制到同一行中,但单元格必须处于不同的顺序(它也是一行,但列和标题有不同的顺序。)
这是我用来根据制造商或关键字在表格中查找产品的代码:
Option Explicit
Dim Key As Boolean
Dim Llave As Boolean
Private Sub BtnBuscar_Click()
If Not Sheet3.Range("C1:C211").Find(Me.DatoBuscado, LookIn:=xlValues, LookAt:=xlPart) Is Nothing Then
If Llave Then
Cells.FindNext(After:=ActiveCell).Select
Fila.Caption = ActiveCell.row
Dato1.Caption = ActiveCell.value
Dato2.Caption = ActiveCell.Offset(0, 1).value
Dato3.Caption = ActiveCell.Offset(0, 2).value
Dato4.Caption = ActiveCell.Offset(0, 4).value
Else
Sheet3.Range("C1:C211").Find(Me.TextBox1, LookIn:=xlValues, LookAt:=xlPart).Select
Fila.Caption = Sheet3.Range("C:C").Find(Me.DatoBuscado, LookIn:=xlValues, LookAt:=xlPart).row
Dato1.Caption = Sheet3.Range("C:C").Find(Me.DatoBuscado, LookIn:=xlValues, LookAt:=xlPart).value
Dato2.Caption = Sheet3.Range("C:C").Find(Me.DatoBuscado, LookIn:=xlValues, LookAt:=xlPart).Offset(0, 1).value
Dato3.Caption = Sheet3.Range("C:C").Find(Me.DatoBuscado, LookIn:=xlValues, LookAt:=xlPart).Offset(0, 2).value
Dato4.Caption = Sheet3.Range("C:C").Find(Me.DatoBuscado, LookIn:=xlValues, LookAt:=xlPart).Offset(0, 3).value
Llave = True
End If
Else
Dato1.Caption = " "
Dato2.Caption = " "
Dato3.Caption = " "
Dato4.Caption = " "
Fila.Caption = " "
MsgBox "Dato Inexistente", 64, ""
End If
End Sub
Private Sub CommandButton1_Click()
If Not Sheet3.Range("E1:E211").Find(Me.TextBox1, LookIn:=xlValues, LookAt:=xlPart) Is Nothing Then
If Key Then
Cells.FindNext(After:=ActiveCell).Select
Fila.Caption = ActiveCell.row
Dato3.Caption = ActiveCell.value
Dato1.Caption = ActiveCell.Offset(0, -2).value
Dato2.Caption = ActiveCell.Offset(0, -1).value
Dato4.Caption = ActiveCell.Offset(0, 1).value
Else
Sheet3.Range("E1:E211").Find(Me.TextBox1, LookIn:=xlValues, LookAt:=xlPart).Select
Fila.Caption = Sheet3.Range("E:E").Find(Me.TextBox1, LookIn:=xlValues, LookAt:=xlPart).row
Dato3.Caption = Sheet3.Range("E:E").Find(Me.TextBox1, LookIn:=xlValues, LookAt:=xlPart).value
Dato1.Caption = Sheet3.Range("E:E").Find(Me.TextBox1, LookIn:=xlValues, LookAt:=xlPart).Offset(0, -2).value
Dato2.Caption = Sheet3.Range("E:E").Find(Me.TextBox1, LookIn:=xlValues, LookAt:=xlPart).Offset(0, -1).value
Dato4.Caption = Sheet3.Range("E:E").Find(Me.TextBox1, LookIn:=xlValues, LookAt:=xlPart).Offset(0, 1).value
Key = True
End If
Else
Dato1.Caption = " "
Dato2.Caption = " "
Dato3.Caption = " "
Dato4.Caption = " "
Fila.Caption = " "
MsgBox "Dato Inexistente", 64, ""
End If
End Sub
Private Sub Dato1_Click()
End Sub
Private Sub Dato3_Click()
End Sub
Private Sub Fila_Click()
End Sub
Private Sub Label8_Click()
End Sub
Private Sub UserForm_Initialize()
Llave = False
Key = False
End Sub
因此,当值匹配时,会选择该单元格:我想将这些单元格和其他一些单元格复制到不同的工作簿中。关键是在工作簿1中我的表格标题是:制作,描述,价格,我还有另一个Excel,我想复制该产品,但标题是'订单是:描述,价格,制造。