number format




  Selection.NumberFormat = "0.00"
---------------
=OFFSET(G1094,-1,0)/OFFSET(G1094,-12,0)-1
----------------

Sub test() ' to select all sheets in the summary workbook
Dim i As Long
Sheet1.Select
For i = 2 To ThisWorkbook.Sheets.Count
    If Sheets(i).Name <> "Summary" Then Sheets(i).Select Replace:=False
Next i
End Sub

 ---------------
Sub LastRowInOneColumn()  'Find the last used row in a Column: column F in this
    Dim LastRow As Long
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
    End With
    MsgBox LastRow
End Sub
---------------------------------


Sub tests() ' to place vlookup in each and every sheet other than summary

Dim i As Long
Sheet1.Select
For i = 2 To ThisWorkbook.Sheets.Count
    If Sheets(i).Name <> "Summary" Then Sheets(i).Select Replace:=False
    a = Range("f7").End(xlDown).Row
    a = a + 1
    Range("f" & a).Select
    ActiveCell.Formula = "="

Next i

End Sub

********************************************************

--ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(R[-17]C[-4],'[Prism_OneDay_MTD Return_Benchmark.xls]Performance Summary'!R9C1:R25C8,17,0)"
    Range("F18").Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(R[-17]C[-4],'[Prism_OneDay_MTD Return_Benchmark.xls]Performance Summary'!R9C1:R25C8,17,0)"
    Range("F19").Select
    Windows("Prism_OneDay_MTD Return_Benchmark.xls").Activate
    Range("A9:J9").Select
    Windows("SantOct 2016 Powershares Daily Check - Copy.xlsx").Activate
    Range("F18").Select





-----------------------------
This example takes a path and name of a workbook and a search term, and searches the specified workbook for the search term. If the search term is found, the address of the result is stored in cell D10 of the current workbook.

VBA

Sub FindAddress()
    'Defining the variables.
    Dim GCell As Range
    Dim Page$, Txt$, MyPath$, MyWB$, MySheet$
   
   
    'The text for which to search.
    Txt = "Hello"
    'The path to the workbook in which to search.
    MyPath = "C:\Your\File\Path\"
    'The name of the workbook in which to search.
    MyWB = "YourFileName.xls"
   
    'Use the current sheet as the place to store the data for which to search.
    MySheet = ActiveSheet.Name
   
    'If an error occurs, use the error handling routine at the end of this file.
    On Error GoTo ErrorHandler
   
    'Turn off screen updating, and then open the target workbook.
    Application.ScreenUpdating = False
    Workbooks.Open FileName:=MyPath & MyWB
   
    'Search for the specified text
    Set GCell = ActiveSheet.Cells.Find(Txt)
   
    'Record the address of the data, along with the date, in the current workbook.
    With ThisWorkbook.ActiveSheet.Range("D10")
        .Value = "Address of " & Txt & ":"
        .Offset(0, 1).Value = "Date:"
        .Offset(1, 0).Value = GCell.Address
        .Offset(1, 1).Value = Date
        .Columns.AutoFit
        .Offset(1, 1).Columns.AutoFit
    End With
   
    'Close the data workbook, without saving any changes, and turn screen updating back on.
    ActiveWorkbook.Close savechanges:=False
    Application.ScreenUpdating = True
Exit Sub

'Error Handling section.
ErrorHandler:
Select Case Err.Number
        'Common error #1: file path or workbook name is wrong.
        Case 1004
            Range("D10:E11").ClearContents
            Application.ScreenUpdating = True
            MsgBox "The workbook " & MyWB & " could not be found in the path" & vbCrLf & MyPath & "."
        Exit Sub
       
        'Common error #2: the specified text wasn't in the target workbook.
        Case 9, 91
            ThisWorkbook.Sheets(MySheet).Range("D10:E11").ClearContents
            Workbooks(MyWB).Close False
            Application.ScreenUpdating = True
            MsgBox "The value " & Txt & " was not found."
        Exit Sub
       
        'General case: turn screenupdating back on, and exit.
        Case Else
            Application.ScreenUpdating = True
        Exit Sub
End Select

End Sub














Comments

Popular posts from this blog

send Mail by outlook from excel sheet

Find and copy the data