Gostaria de criar uma macro que percorresse a planilha deletando todas as
colunas vazias, de modo que as colunas contendo dados sejam agrupadas.
Como posso fazer isso?
Sub RemoveBlankCols()
Dim objSheet As Worksheet
Dim RowsCount As Long
Set objSheet = Worksheets("Plan1") 'Nome da sua planilha
RowsCount = objSheet.Rows.Count
For Each objCol In objSheet.Columns
RowsCountAux = objSheet.Cells(1, objCol.Column).End(xlDown).Row
If RowsCountAux = RowsCount Then
objCol.EntireColumn.Delete
End If
Next
End Sub
Espero ter ajudado
--
Rodrigo Ferreira
Regards from Brazil
"jordaojunior" <jordao...@discussions.microsoft.com> escreveu na mensagem
news:8DFD23CC-AF61-43EC...@microsoft.com...
Pode me ajudar nessa situação?
Obrigado!
Sub formatar2()
'
' Macro1 Macro
'
' Atalho do teclado: Ctrl+y
'
Windows("snp.xlsx").Activate
Dim objSheet As Worksheet
Dim RowsCount As Long
Set objSheet = Worksheets("haplótipos") 'Nome da planilha
RowsCount = objSheet.Rows.Count
For Each objCol In objSheet.Columns
RowsCountAux = objSheet.Cells(1, objCol.Column).End(xlDown).Row
If RowsCountAux = RowsCount Then
objCol.EntireColumn.Delete
End If
Next
End Sub
------------------------------------------
Tente o seguinte:
Sub formatar2()
'
' Macro1 Macro
'
' Atalho do teclado: Ctrl+y
'
'Windows("snp.xlsx").Activate
Dim objSheet As Worksheet
Dim RowFim As Long
Set objSheet = Worksheets("Plan1") 'Nome da planilha
RowIni = 3
RowFim = 98
For Each objCol In objSheet.Columns
For Each objCell In objCol.Cells
'Debug.Print objCell.Address
If objCell.Row > RowIni Then
If objCell.Value <> "" Then
TemValor = True
Exit For
Else
TemValor = False
End If
If objCell.Row = RowFim Then
Exit For
End If
Else
TemValor = True
End If
Next
If Not TemValor Then
'Stop
objCol.EntireColumn.Delete
End If
Next
End Sub
Espero ter ajudado
--
Rodrigo Ferreira
Regards from Brazil
"jordaojunior" <jordao...@discussions.microsoft.com> escreveu na mensagem
news:FC91773A-6E7A-4E9F...@microsoft.com...
Sabe me dizer?
Obrigado mais uma vez.
Abraços,
Hamilton Jordão
Não sei se estou a ver mal mas acho que te esquecestes de declarar a
variável " TemValor" como Boolean?
Dim TemValor As Boolean
Cpts
Tito
--
Meu site office: http://officept.mvps.org/
Meu Site versão Blog: http://officept.blogspot.com/
FEEDs (Atom): http://officept.blogspot.com/feeds/posts/default
"Rodrigo Ferreira" <cab...@hotmail.com> wrote in message
news:OUyvGed1...@TK2MSFTNGP05.phx.gbl...
Obs.: O nome da sua planilha é mesmo "Plan1"?
--
Rodrigo Ferreira
Regards from Brazil
"jordaojunior" <jordao...@discussions.microsoft.com> escreveu na mensagem
news:C01267A0-059D-4F9F...@microsoft.com...
Obrigado pela observação.
--
Rodrigo Ferreira
Regards from Brazil
"Joao Livio [MVP]" <jli...@online.mvps.org> escreveu na mensagem
news:Oo0hTee1...@TK2MSFTNGP06.phx.gbl...
Aqui tb não funciona. (Excel 2007).
A Macro começa na coluna $G$, quando lá passa manda os valores para a coluna
$D$, e esta heinn?, não tens de dizer o que é "objCol" e "objCell" ?
Não será mais qq deste género?
Sub ApagaColunasBrancas()
Dim x As Long
With ActiveSheet
For x = .Cells.SpecialCells(xlCellTypeLastCell).Row _
To 1 Step -1
If WorksheetFunction.CountA(.Rows(x)) = 0 Then
ActiveSheet.Rows(x).Delete
End If
Next
End With
End Sub
--
Meu site office: http://officept.mvps.org/
Meu Site versão Blog: http://officept.blogspot.com/
FEEDs (Atom): http://officept.blogspot.com/feeds/posts/default
"Rodrigo Ferreira" <cab...@hotmail.com> wrote in message
news:uNtU5if1...@TK2MSFTNGP02.phx.gbl...
Tenta
Sub ApagaLinhasBrancas()
Dim x As Long
With ActiveSheet
For x = .Cells.SpecialCells(xlCellTypeLastCell).Row _
To 1 Step -1
If WorksheetFunction.CountA(.Rows(x)) = 0 Then
ActiveSheet.Rows(x).Delete
End If
Next
End With
End Sub
--
Meu site office: http://officept.mvps.org/
Meu Site versão Blog: http://officept.blogspot.com/
FEEDs (Atom): http://officept.blogspot.com/feeds/posts/default
"jordaojunior" <jordao...@discussions.microsoft.com> wrote in message
news:8DFD23CC-AF61-43EC...@microsoft.com...
--
Rodrigo Ferreira
Regards from Brazil
"Joao Livio [MVP]" <jli...@online.mvps.org> escreveu na mensagem
news:eOiHCVh1...@TK2MSFTNGP06.phx.gbl...
Sub ApagaColunasBrancas()
Dim x As Long
RowIni = 3
RowFim = 98
CountBlankRows = RowFim - RowIni + 1
With ActiveSheet
For x = .Cells.SpecialCells(xlCellTypeLastCell).Column To 1 Step -1
If WorksheetFunction.CountIf(Range(Cells(RowIni, x).Address _
& ":" & Cells(RowFim, x).Address), "") = CountBlankRows Then
ActiveSheet.Columns(x).Delete
End If
Next
End With
End Sub
--
Rodrigo Ferreira
Regards from Brazil
--
Rodrigo Ferreira
Regards from Brazil
"jordaojunior" <jordao...@discussions.microsoft.com> escreveu na mensagem
news:C01267A0-059D-4F9F...@microsoft.com...
Cpts
Tito
--
Meu site office: http://officept.mvps.org/
Meu Site versão Blog: http://officept.blogspot.com/
FEEDs (Atom): http://officept.blogspot.com/feeds/posts/default
"Rodrigo Ferreira" <cab...@hotmail.com> wrote in message
news:e$Gqiuh1H...@TK2MSFTNGP06.phx.gbl...