Saturday 24 March 2018

VBA in Excel - Properties, Methods and Events - 3



1.  Code to replace a value of Gowtham with super in Column C


Sub FindMatchingValue()
    Dim i As Integer, intValueToFind As String
   
    intValueToFind = "gowtham"
    For i = 1 To 7   ' Revise the 500 to include all of your values
        If Cells(i, 3).Value = intValueToFind Then
        Range("C" & i) = "super"
       
            Exit Sub
        End If
    Next i
    ' This MsgBox will only show if the loop completes with no success
    MsgBox ("Value not found in the range!")
End Sub




2.  Code to paste special with format and text


Sheet3.Range("a1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheet3.Range("a1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False



3. Code to filter with multiple critera


ActiveSheet.Range("a3:aa100000").AutoFilter Field:=15, Criteria1:="UTDRIP", Operator:=xlOr, Criteria2:="DRIP"
ActiveSheet.Range("a3:aa100000").AutoFilter Field:=5, Criteria1:="OS-PUR", Operator:=xlOr, Criteria2:="OS-SAL"

No comments:

Post a Comment