Results 1 to 10 of 26

Thread: Misc. Leonardo1234 rider@1234 vixer. Highlighting. Simple Early stuff. Avinash Introduction

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Quote Originally Posted by fixer View Post
    ...
    And one more thing Sir vba is placed in a seperate file means it is not placed in 9.xlsb and 1.xls it will be placed in a different file and all files are located in a same place (9.xlsb,1.xls and vba placed file all are located in same place)
    only one file is opened that is vba code placed file
    OK. I will use file Macro.xlsm for the Macro, Sub Vixer4()

    Code:
    Sub Vixer4() ' http://www.excelfox.com/forum/showthread.php/2353-add-by-vba?p=11425&viewfull=1#post11425
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    Dim Wb1 As Workbook, Wbm As Workbook ' (These will be set later when the workbooks are opened)
    Dim strWb1 As String: Let strWb1 = "1.xls"
    Dim strWbm As String: Let strWbm = "9.xlsb"
    '1b) Worksheets info
    Dim Ws1 As Worksheet, Wsm As Worksheet ' (These will be set later when the workbooks are opened)
    Dim Lr As Long: Let Lr = 121 ' For this example I am using 120 rows of data ( 2 - 121 )
    Rem 2 Open  1.xls  file
    'Workbooks.Open Filename:= "F:\Excel0202015Jan2016\ExcelFox\vixer\Von Vixer\1.xls"
    'Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "1.xls"   '   all files are located in a same place     '  9.xlsb  and 1.xls  are in the same folder, ( so I can use ThisWorkbook.Path to get the string path to the folder )
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb1
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWbm
     Set Wbm = ActiveWorkbook '
     Set Wsm = Wbm.Worksheets.Item(1)
    
    Rem 3  add all the data in column H of  1.xls  and paste the result in K9 of vba contained file in sheet1
     'Wbm.Activate: Wsm.Range("K9").Select: Application.Calculation = xlCalculationAutomatic
    ' Let Wsm.Range("K9").Value = "=SUM('[1.xls]1-Sheet1'!$H$2:$H$121)"   '  Note:  In VBA we must write the formulas in English
    ' Let Wsm.Range("K9").Value = "=SUM('[" & strWb1 & "]1-Sheet1'!$H$2:$H$121)"
    ' Let Wsm.Range("K9").Value = "=SUM('[" & strWb1 & "]" & Ws1.Name & "'!$H$2:$H$121)"
     Let Wsm.Range("K9").Value = "=SUM('[" & strWb1 & "]" & Ws1.Name & "'!$H$2:$H$" & Lr & ")"
     Let Wsm.Range("K9").Value = Wsm.Range("K9").Value ' change cell content from formula to its value
    Rem 4 close the files
     Wbm.Close savechanges:=True
     Wb1.Close
    End Sub


    Alan
    Attached Files Attached Files

Similar Threads

  1. Class Stuff: VBA Custom Classes & Objects, Class Modules
    By DocAElstein in forum Excel and VBA Tips and Tricks
    Replies: 29
    Last Post: 06-02-2024, 01:49 PM
  2. Replies: 9
    Last Post: 05-13-2021, 02:31 PM
  3. Replies: 2
    Last Post: 06-23-2019, 03:30 PM
  4. VBA Range.Sort with arrays. Alternative for simple use.
    By DocAElstein in forum Excel and VBA Tips and Tricks
    Replies: 23
    Last Post: 04-22-2019, 12:31 PM
  5. Free And Simple Excel Based Gantt Chart
    By Excel Fox in forum Download Center
    Replies: 0
    Last Post: 05-02-2013, 03:16 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •