Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
Por werlewow
Posts
#43371
Boa Tarde a todos, estou tentando desenvolver um código onde o usuário seleciona na coluna A (ou qualquer outra) as linhas em que ele deseja deletar, e o seu nome, e ao executar a macro ele deleta toda a linha.
Na planilha em anexo esta tudo funcionando como deveria, ao clicar no botão, digite seu nome e depois selecione a célula A3, por exemplo, a macro ira excluir toda linha 3, além de add na outra planilha o nº do pedido excluído e o nome do usuário.

O problema ocorre se o usuário tenta selecionar mais de 1 valor, por exemplo, as células A3:A4, ai o código não funciona...Alguém pode me ajudar para que funcione?

Obrigado.
Você não está autorizado a ver ou baixar esse anexo.
Por osvaldomp
#43430
Código: Selecionar todos
Sub ExcluiLinhas()
 Dim r As Range
  For Each r In Selection
   Sheets("Planilha2").Cells(Rows.Count, 1).End(3)(2) = Application.UserName
   Sheets("Planilha2").Cells(Rows.Count, 2).End(3)(2) = r.Value
   r.Value = ""
  Next r
 Range("A2:A" & Cells(Rows.Count, 1).End(3).Row).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
Selecione quantos pedidos quiser na coluna A e rode o código.
Por werlewow
Posts
#43480
Obrigado! Não resolveu totalmente, mas adaptei o código e deu certinho... Vou por abaixo caso alguém precise.

Sub excluir()
ActiveSheet.Unprotect "123mudar"
Dim r As Range
Dim myRange As Range
'On Error GoTo finaliza
Set myRange = Application.InputBox(Prompt:= _
"Selecione na coluna de pedidos todas as linhas que deseja excluir!", _
Title:="Excluir Pedido", Type:=8)

If myRange.Column <> 2 Then
MsgBox "Selecione os dados da coluna de pedidos somente"
Exit Sub

Else
If myRange Is Nothing Then

GoTo finaliza
Else


myRange.Select
End If
End If
For Each r In Selection
Sheets("Planilha2").Cells(Rows.Count, 2).End(3)(2) = Application.UserName
Sheets("Planilha2").Cells(Rows.Count, 1).End(3)(2) = r.Value
Sheets("Planilha2").Cells(Rows.Count, 3).End(3)(2) = Now()
r.Value = ""
Next r

Range("b5:b" & Cells(Rows.Count, 2).End(3).Row).SpecialCells(xlBlanks).EntireRow.Select

Selection.Delete Shift:=xlUp


MsgBox "Seu pedido foi excluido com sucesso"

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, Password:="123mudar"
Exit Sub

finaliza:
MsgBox "Operação cancelada"
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, Password:="123mudar"
Exit Sub

End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord