Combining 2 VBA codes

Solved/Closed
SARC Posts 29 Registration date Saturday August 7, 2010 Status Member Last seen August 31, 2010 - Aug 7, 2010 at 01:01 AM
SARC Posts 29 Registration date Saturday August 7, 2010 Status Member Last seen August 31, 2010 - Aug 17, 2010 at 10:59 PM
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 January 28, 2010 Status Contributor Last seen May 5, 2022 766
Aug 7, 2010 at 07:34 PM
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 
1
SARC Posts 29 Registration date Saturday August 7, 2010 Status Member Last seen August 31, 2010
Aug 7, 2010 at 09:20 PM
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
0
SARC Posts 29 Registration date Saturday August 7, 2010 Status Member Last seen August 31, 2010
Aug 7, 2010 at 09:24 PM
forgot to tell you what I wanted..... is there a way to hide any column if a value is pasted on a cell?
0