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"

Tuesday, 6 March 2018

Veedu - Indra parthasarathy




What a nostalgic depiction of the grandeur of olden day's Kumbakonam and blotless sentiments of pristine characters of the story !!!. 






At the end , this creation of art throws a question  in my mind- Why it has become difficult to find  such true and altruistic hearts in the world today..?

Sunday, 25 February 2018

Wise Words- 4


Two impressive and thought-provoking dialogues from the movie “Vikram Vedha”

·      Dei… Vidhi, vidhi nu aayiram thadavai sollitiru.. Life chance-a eduthutu vandhu “sedhu.. indha pidinu kaila kodukadhu”. Unnaku onnu thevaina, adhukaga try panama irukradhudhan thappu.


·   Eppayum prachanai-na prachanai ennanu paarkadha.. Prachanaikaana kaaranam ennanu paaru.



Wise Words- 3




·             Have the courage to follow your heart and intuition. They somehow know what you truly want to become

·         Don’t be trapped by dogma – which is living with the results of other people’s thinking.

·         Your time is limited, so don’t waste it living someone else’s life.

·             If you don’t love something, you’re not going to go the extra mile, work the extra weekend, challenge the status quo as much










Thursday, 22 February 2018

VBA in Excel - Properties, Methods and Events - 2



1.

Selection.SpecialCells(xlCellTypeBlanks).Select

This statement selects the blank special cells of the original selection. (The word SpecialCells is a method that handles many of the options in the Go To Special dialog box.)


2. 

Selection.FormulaR1C1 = "=R[-1]C"

This statement assigns =R[-1]C as the formula for the entire selection. When you entered the formula, the formula you saw was =C2, not =R[-1]C. The formula =C2 really means "get the value from the cell just above me," but only if the active cell happens to be cell C3. The formula =R[-1]C also means "get the value from the cell just above me," but without regard for which cell is active.
You could change this statement to Selection.Formula = "=C2" and the macro would work exactly the same—provided that the order file you use when you run the macro is identical to the order file you used when you recorded the macro and that the active cell happens to be cell C3 when the macro runs. However, if the command that selects blanks produces a different active cell, the revised macro will fail. The macro recorder uses R1C1 notation so that your macro will always work correctly.


3. 

Selection.CurrentRegion.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select

These statements select the current region, convert the formulas to values, cancel copy mode, and select cell A1.


4.


Sub AddDates()
    Range("A1").Select
    Selection.EntireColumn.Insert
    ActiveCell.FormulaR1C1 = "Date"
    Range("A2").Select
    Selection.CurrentRegion.Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.FormulaR1C1 = "Nov-2007"
    Range("A1").Select
End Sub


This macro is pretty straightforward. Notice that the statement that enters the word Date uses the word ActiveCell as the object, changing the "formula" of only the active cell, whereas the statement that enters the actual date uses the word Selection as the object, changing the "formula" of the entire range of selected cells. When you enter a formula using the Enter key alone, the macro uses the word ActiveCell. When you enter a formula using Ctrl+Enter, the macro uses the word Selection. (If the selection consists of only a single cell, ActiveCell and Selection are equivalent.)
In addition, using just the Enter key changes the selection to the next cell down. That's why the Range("A2").Select statement is in the macro. It doesn't hurt anything, but it is also unnecessary. Removing unnecessary statements from a recorded macro makes it easier to read, and easier to modify in the future if you ever need to.


5. 

Selection.End(xlDown).Select
This statement is equivalent to pressing Ctrl+Down Arrow. It starts with the active cell, searches down to the last nonblank cell, and selects that cell.


6.
 Workbooks.Open Filename:="C:\MSP\ExcelVBA07SBS\Orders.xlsx"



In the Visual Basic editor window, the statement that opens the master list should be highlighted:
Workbooks.Open Filename:="C:\MSP\ExcelVBA07SBS\Orders.xlsx"
This statement opens the master list workbook.
TIP
If you remove the path from the file name, leaving only the actual file, the macro looks for the file in the current folder. That would be useful if you move the project to a new folder. However, if the master list is always in the same location, but the source file may be in different locations, it is better to leave the full path of the master file.


7.


ActiveWorkbook.Close SaveChanges:=False
The SaveChanges argument answers the dialog box's question before it even gets asked. While testing, you can have the macro not save the workbook. Once you're ready to really use the macro, you can change the argument to True.

8.


ActiveWindow.SelectedSheets.Delete
The statement refers to the "selected sheets of the active window" because it's possible to select and delete multiple sheets at the same time. (Press and hold the Ctrl key as you click several sheet tabs to see how you can select multiple sheets. Then click an unselected sheet without using the Ctrl key to deselect the sheets.) Because you're deleting only one sheet, you could change the statement to ActiveSheet.Delete if you wanted, but that isn't necessary.


9.


Application.DisplayAlerts = False

DisplayAlerts is a property of the Excel application. When you set the value of this property to False, any confirmation prompts that you would normally see are treated as if you had selected the default answer. The DisplayAlerts setting lasts only until the macro finishes running, so you don't need to set it back to True. You do, however, need to be careful to never run this macro when the active sheet is something you care about. Naturally, you should also be careful to save your work often and keep backup copies.


(From the book

Microsoft® Office Excel® 2007 Visual Basic® for Applications Step by Step 

by Reed Jacobson)