como copiar automaticamente linhas para a nova planilha VBA Excel
Eu estou tentandoauto-copy
uma linha de ummaster
spreadsheet
para outrospreadsheet
. Isso deve ocorrer quando o valor de entrada nomaster
é igual aX
.
Então seX
é inserido emColumn A
nomaster
, entãoauto-copy
separarspreadsheet
(vamos chamá-lo de X). BasicamenteSheet X
sempre deve conter uma cópia exata de todos osrows
emmaster
OndeColumn A = X
.
Não tenho certeza se isso afetaria oauto-copy
mas omaster sheet
contém umscript
que esconde / mostraColumns
. Então seX
é inserido emColumn A
nomaster sheet
entãoColumn B,C
ficará oculto eD,E,F
será mostrado
Um exemplo do que estou tentando obter é mostrado abaixo:
Master Sheet
contém esta informação. Mas seX
é inserido emColumn A
sóD,E,F
será visível
A B C D E F
X 4 5 6
Y 1 2 3 4 5
X 1 2 3
X Folha:
A D E F
X 4 5 6
X 1 2 3
Isto é o que eu tentei
Sub FilterAndCopy()
Dim sht1 As Worksheet, sht2 As Worksheet
Set sht1 = Sheets("Master")
Set sht2 = Sheets("X")
Intersect(sht2.UsedRange, sht2.Rows("2:" & Rows.Count)).ClearContents
sht1.Cells(1, 1).CurrentRegion.AutoFilter
sht1.Cells(1, 1).CurrentRegion.AutoFilter 1, "X"
sht1.Cells(1, 1).CurrentRegion.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Copy sht2.Cells(2, 1)
sht1.Cells(1, 1).CurrentRegion.AutoFilter
End Sub
Mas retorna um erro:
Microsoft Visual Basic
Object variable with block variable not set