Estou com um problema de copiar / colar de um arquivo do Excel para outro.
Eu tenho uma pasta de trabalho com formulários para inserir dados. Recentemente, adicionei um sub para capitalizar automaticamente as células de entrada.
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim rng As Range
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set rng = Target.Parent.Range("B11:C47")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here...)
Application.EnableEvents = False
Target.Value = UCase(Application.WorksheetFunction.Substitute(Target.Value, " ", ""))
Application.EnableEvents = True
End Sub
Agora, quando copio e colo um intervalo de células (Ex: B2: B12) que possuem células vazias misturadas a uma versão mais antiga do mesmo arquivo sem o sub, algumas das células vazias são causando problemas de fórmula. Isso desaparece se as células coladas em branco forem ativadas (clique duas vezes ou exclua).
Eu não tenho como modificar a versão mais antiga do arquivo, pois ele foi distribuído para várias pessoas e seria impossível corrigir todas elas.
Isso parece acontecer aleatoriamente, pois nem todas as células vazias causam o problema e nem sempre são as mesmas células. Eu tentei = CODE (), = VALUE (), = ISTEXT (), = ISNUMBER () para encontrar o que está realmente na célula, mas não consigo obter qualquer valor, apenas que a célula é texto (como todos os as células de entrada são formatadas como texto).
Para tentar responder a quaisquer perguntas que possam surgir:
-
Copiar / colar apenas valores, etc ... resulta no mesmo problema
-
Copiar / colar dentro de cada arquivo funciona sem problemas
-
Ir do arquivo antigo para o novo arquivo funciona
Além de simplesmente entrar e "excluir" os "valores" de todas as células "vazias" a cada vez, existe uma maneira de evitar que essas células coladas vazias sejam ativadas no arquivo antigo? Estou assumindo que o problema surge do sub como este problema não estava lá nas versões anteriores deste arquivo.
EDITAR
Todo o código de uma das planilhas em questão:
Private Sub Worksheet_Activate()
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
End Sub
Private Sub Worksheet_Calculate()
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim rng As Range
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set rng = Target.Parent.Range("B11:C47")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here...)
Application.EnableEvents = False
Target.Value = UCase(Application.WorksheetFunction.Substitute(Target.Value, " ", ""))
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Deactivate()
End Sub
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
End Sub
Private Sub Worksheet_PivotTableAfterValueChange(ByVal TargetPivotTable As PivotTable, ByVal TargetRange As Range)
End Sub
Private Sub Worksheet_PivotTableBeforeAllocateChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End Sub
Private Sub Worksheet_PivotTableBeforeCommitChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)
End Sub
Private Sub Worksheet_PivotTableBeforeDiscardChanges(ByVal TargetPivotTable As PivotTable, ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long)
End Sub
Private Sub Worksheet_PivotTableChangeSync(ByVal Target As PivotTable)
End Sub
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub