Combining 2 VBA codes

Solved/Closed
SARC Posts 29 Registration date Saturday 7 August 2010 Status Member Last seen 31 August 2010 - 7 Aug 2010 à 01:01
SARC Posts 29 Registration date Saturday 7 August 2010 Status Member Last seen 31 August 2010 - 17 Aug 2010 à 22:59
Hi.. I need to combine 2 codes together. I'm very new to VBA. These are the 2 codes I need to combine. when I paste the 2nd code it doesnt work properly

Code1
Private Sub Worksheet_Change(ByVal Target As Range)
'Erik Van Geit
'only allow PasteValues

If Application.CutCopyMode = False Then Exit Sub

With Application
.ScreenUpdating = False
.EnableEvents = False
.Undo
Target.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
.EnableEvents = True
.ScreenUpdating = True
End With

End Sub

Code2
Private Sub Worksheet_Change(ByVal Target As Range)

If Range("A2") = >1 Then
Columns("A").EntireColumn.Hidden = True
End If

End Sub


any help pls......

Related:

2 responses

rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
7 Aug 2010 à 19:34
There is lot of ambiguity on what is your intentions


This is presuming that irrespective of fact if you paste the value or not you want to hide the column

Private Sub Worksheet_Change(ByVal Target As Range) 
'Erik Van Geit 
'only allow PasteValues 

    If Application.CutCopyMode <> False Then 
     
        With Application 
            .ScreenUpdating = False 
            .EnableEvents = False 
            .Undo              
            
            Target.PasteSpecial _
                        Paste:=xlPasteValues, _
                        Operation:=xlNone, _
                        SkipBlanks:=False, _
                        Transpose:=False
             
            .EnableEvents = True 
            .ScreenUpdating = True 

        End With 
     
    End If 
     
    If Range("A2") >= 1 Then Columns("A").EntireColumn.Hidden = True 
     
End Sub 
SARC Posts 29 Registration date Saturday 7 August 2010 Status Member Last seen 31 August 2010
7 Aug 2010 à 21:20
Thanks rizvi...... your my hero.............. This is exactly what I wanted. I'm trying to develop some sort of stock updating system this is just 1 phase in it. would you be able to help me out with a few more things..... Thanks again for the code
SARC Posts 29 Registration date Saturday 7 August 2010 Status Member Last seen 31 August 2010
7 Aug 2010 à 21:24
forgot to tell you what I wanted..... is there a way to hide any column if a value is pasted on a cell?