Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 26

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

  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    From Here:
    https://www.excelforum.com/excel-pro...dd-by-vba.html
    https://www.excelforum.com/excel-pro...ml#post5177301
    https://www.excelforum.com/excel-pro...ml#post5177506



    Quote Originally Posted by kinjal124 View Post
    See the attached files
    Vba is placed in a "separate file"
    Open 1.xls file
    Calculate the data add all the data in column H and paste the result in K9 of vba contained file in sheet1
    and close the 1.xls file
    Hello,
    Note:
    _ I am assuming that the "separate file" is _ 9.xlsb _ , that is to say, the separate file with the VBA macro in is _ 9.xlsb
    _ I assume that _ 9.xlsb _ and _ 1.xls _ are in the same folder, ( so I can use ThisWorkbook.Path to get the string path to the folder )


    This I got from the macro recorder:
    Code:
    ' From macro recorder:
    Sub Makro1()
    '
    ' Makro1 Makro
    '
    
    '   Open 1.xls file
        Workbooks.Open Filename:= _
            "F:\Excel0202015Jan2016\ExcelFox\vixer\Von Vixer\1.xls"
        Windows("9.xlsb").Activate
        
    '   Type in a formula to get the sum  .....  add all the data in column H and paste the result in K9
        Range("K9").Select
        ActiveCell.FormulaR1C1 = "=SUM('[1.xls]1-Sheet1'!R2C8:R121C8)"
        Range("K10").Select
        Windows("1.xls").Activate
        
    '   close the 1.xls file
        ActiveWindow.Close
    End Sub
    '
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ' Closed workbook reference   =SUMME('F:\Excel0202015Jan2016\ExcelFox\vixer\Von Vixer\[1.xls]1-Sheet1'!$H$2:$H$121)
    ' Open workbook reference     =SUMME('[1.xls]1-Sheet1'!$H$2:$H$121)
    This I wrote myself:
    Code:
    Sub Vixer3a() ' http://www.excelfox.com/forum/showthread.php/2353-add-by-vba?p=11421&viewfull=1#post11421
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    Dim Wb1 As Workbook ' (will be set later when the workbook is opened)
    Dim strWb1 As String: Let strWb1 = "1.xls"
    Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' I am assuming that this workbook is the seperate macro workbook
    '1b) Worksheets info
    Dim Ws1 As Worksheet ' (will be set later when the workbook is opened)
    Dim Wsm As Worksheet
    'Set Wsm = ThisWorkbook.Worksheets.Item(1) ' The first worksheet in this workbook ..
    Set Wsm = ThisWorkbook.Worksheets("Sheet1") '     ..    use tab Name as alternative                                     http://www.excelfox.com/forum/showthread.php/2349-Find-percentage-by-vba?p=11400&viewfull=1#post11400
    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"         '  I assume that   9.xlsb   and   1.xls   are in the same folder, ( so I can use ThisWorkbook.Path to get the string path to the folder of  1.xls)    
     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)
    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 1.xls file
     Wb1.Close
    End Sub
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ' Closed workbook reference   =SUMME('F:\Excel0202015Jan2016\ExcelFox\vixer\Von Vixer\[1.xls]1-Sheet1'!$H$2:$H$121)
    ' Open workbook reference     =SUMME('[1.xls]1-Sheet1'!$H$2:$H$121)
    
    
    
    Sub Oops()
    Application.Calculation = xlCalculationAutomatic
    End Sub


    Alan
    Attached Files Attached Files
    Last edited by DocAElstein; 08-17-2019 at 08:56 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  2. #12
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Thnx Doc Sir for giving ur precious time and Great support to this post
    But i need a simple code only one code that i will run and process done
    i want only one code and it should done what i want is put all the details in one code like that
    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
    So it is my request plz have a relook and help me Sir
    Thnx Alot for ur Great Support
    Last edited by fixer; 08-17-2019 at 09:52 PM.

  3. #13
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    Quote Originally Posted by fixer View Post
    i need a simple code only one code that i will run and process done
    i want only one code and it should done what i want is put all the details in one code like that
    All macros are the same. They do the same thing.
    Sub Makro1() is the same as Sub Vixer3a()
    You do not need the two macros. You can use either ….

    And here is another one
    Code:
    Sub Vixer3b() ' http://www.excelfox.com/forum/showthread.php/2353-add-by-vba?p=11425&viewfull=1#post11425
     Workbooks.Open ThisWorkbook.Path & "\" & "1.xls"
     ThisWorkbook.Activate ' If this workbook is active, then an unqualified range in a normal code module will revert to the active worksheet
     Range("K9").Value = "=SUM('[1.xls]1-Sheet1'!$H$2:$H$121)"
     Range("K9").Value = Range("K9").Value
     Workbooks("1.xls").Close
    End Sub

    Sub Makro1() = Sub Vixer3a() = Sub Vixer3b()









    I ( Alan ) prefer to make detailed codes. This is good for learning and this is good for teaching and this makes it easier to modify the coding later.
    Using simple codes will waste everyone's time because you keep asking almost the same question every time. So soon no one will want to help you any more. That is what happened at Eileen's Lounge. ( https://www.eileenslounge.com/viewto...253802#p253804 )

    मी तपशीलवार कोड बनविणे पसंत करतो. हे शिकण्यासाठी चांगले आहे आणि ते अध्यापनासाठी चांगले आहे आणि कोडिंग नंतर सुधारणे सोपे करते.
    साधे कोड वापरल्याने प्रत्येकाचा वेळ वाया जाईल कारण आपणास वारंवार समान प्रश्न विचारला जातो. कोणीही लवकरच आपल्याला मदत करू इच्छित नाही कारण आपण शिकणार नाही. आपण शिकत नसल्यास आम्ही आपल्यासाठी कार्य करीत आहोत.
    मध्ये Eileen's Lounge तेच घडले.. ( https://www.eileenslounge.com/viewto...253802#p253804 )





    Alan
    Last edited by DocAElstein; 08-18-2019 at 04:08 PM.

  4. #14
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    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

  5. #15
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Thnx Doc Sir for giving ur Great Great Support to this post
    Love U Sir









    Moderator Translation:
    I am a total fucking idiot dim pig shit for brains, so just give me a macro that does what I want, even though most of the time I aint got a fucking clue myself what I want because I am such a total fucking spacko ... and never mind anyway, fuck off you mug, as some other twat gave me a macro at one of my many duplicated cross postings.......( Intro to Avinash Singh... https://excelfox.com/forum/showthrea...h-Introduction )
    Last edited by DocAElstein; 06-23-2020 at 02:49 PM.

  6. #16
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

    Copy Cell Based On Column Position Of Highlighted Cell In Matched Row

    all files are located in a same place
    vba code will be placed in a macro.xlsm
    my first file name is 1.xlsx
    my second file name is 2.xlsx
    open both the files
    in 1.xlsx column A consist of stock name and 1.xlsx has headers in the first row
    In 2.xlsx column B consist of stock name and 2.xlsx has headers in the first row
    see the pic which i attached
    now what i need match column A stock name of 1.xlsx with column B of 2. xlsx and if it matches then copy the yellow highlighted colured cell data in that row of 1.xlsx and paste it to column L OF 2.xlsx
    save and close both the file after doing the process
    So plz help me sir in solving this problem sir
    Attached Images Attached Images
    • File Type: jpg 2.jpg (20.4 KB, 9 views)
    • File Type: png 1.PNG (7.1 KB, 9 views)
    Last edited by DocAElstein; 03-06-2020 at 11:15 PM.

  7. #17
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10

    Copy and paste by highlighted colour Paste Highlighted Cells From Matched Column Rows

    Hi

    Your explanation is ambiguous. It could be interpreted in different ways.
    So I will interpret it as I choose. It will be luck if it gives you what you want......




    Looking for highlighted cells requires interaction to the spreadsheet, since no format information is held in Excel values, that is to say using the .Value Property for the complete range will only distinguish Values, Formulas, Dates and Empty cells

    But some worksheet functions are efficient, for example Range.Find , SpecilaCells, Copy, Offsett.

    The solution that I have chosen to do will involve an initial adjustment so that I can detect the highlighted cells in a different way. Rem 2 makes the cell values formulas: http://www.excelfox.com/forum/showth...ll=1#post12570

    Here is the macro, also in macro.xlsm

    Code:
    Sub PasteHighlightedCellsFromMatchedColumnRows() ' http://www.excelfox.com/forum/showthread.php/2425-Copy-and-paste-by-highlighted-colour
    Rem 1 Worksheets info
    Dim Ws1 As Worksheet, Ws2 As Worksheet
     Set Ws1 = Workbooks("1.xlsx").Worksheets.Item(1): Set Ws2 = Workbooks("2.xlsx").Worksheets.Item(1)
    Rem 2  .... initial adjustment so that I can detect the highlighted cells in a different way
    Dim Rng As Range
      For Each Rng In Ws1.UsedRange.Offset(0, 2).Resize(, Ws1.UsedRange.Columns.Count - 2) ' We are intersted in the range offset 2 columns to the left of size 2 columns less than the main used range
        If Rng.Interior.Color = 65535 Then
         Let Rng.Value = "=" & """" & Rng.Value & """"
        Else
        End If
      Next Rng
    Rem 3  match column A stock name of 1.xlsx with column B of 2.xlsx and if it matches then copy the yellow highlighted colured cell data in that row of 1.xlsx and paste it to column L OF 2.xlsx
    Dim Lr1 As Long: Let Lr1 = Ws1.UsedRange.Rows.Count
      For Each Rng In Ws1.Range("A2:A" & Lr1 & "") '  Ws1 column A
      Dim Lr2 As Long: Let Lr2 = Ws2.UsedRange.Rows.Count
      Dim SrchRng As Range: Set SrchRng = Ws2.Range("B2:B" & Lr2 & "")
      Dim RngMtch As Range
       Set RngMtch = SrchRng.Find(what:=Rng.Value, After:=Ws2.Range("B2"), LookAt:=xlWhole, searchorder:=xlNext, MatchCase:=True) '
        If RngMtch Is Nothing Then
        
        Else ' a cell from column a 1.xlsx is matched to a cell from column B 2.xlsx
        ' copy the yellow highlighted colured cell data in that row of 1.xlsx
         Rng.Offset(0, 1).Resize(, Ws1.UsedRange.Columns.Count - 1).SpecialCells(xlCellTypeFormulas, xlNumbers + xlTextValues).Copy
        ' paste it to column L OF 2.xlsx
         Ws2.Range("L" & RngMtch.Row & "").PasteSpecial Paste:=xlPasteValues
        End If
      Next Rng ' Ws1 column A
    Rem 4 save and close both the file after doing the process
    Workbooks("1.xlsx").Close savechanges:=False
    Workbooks("2.xlsx").Close savechanges:=True
    End Sub

    See also here: http://www.excelfox.com/forum/showth...ll=1#post12570





    Alan








    1.xlsx : https://app.box.com/s/dgufdfvw3lm3knkvwvp0xgiqpwarqf69
    2.xlsx : https://app.box.com/s/51cykk4zd6ldan8puz70o3zyj0e17rwf
    macro.xlsm : https://app.box.com/s/tbis0g4n6l6386df6xjwh4cirbtgphzl
    Last edited by DocAElstein; 03-06-2020 at 11:15 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  8. #18
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Code:
    Rng.Offset(0, 1).Resize(, Ws1.UsedRange.Columns.Count - 1).SpecialCells(xlCellTypeFormulas, xlNumbers + xlTextValues).Copy
    This line has error Doc Sir Plz have a look sir

  9. #19
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    .SpecialCells will error if no cells are found
    So that code line will error if there are no highlighted cells in the matched row

    It would be useful if you upload a small data sample, example files
    1.xlsx
    2.xlsx
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  10. #20
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    I am sorry Doc sir, i made a mistake in providing the info to u sir
    plz see now each and every details is mentioned in the files
    from data to result everything is mentioned sir
    plz see the sample file
    Attached Files Attached Files

Similar Threads

  1. Replies: 9
    Last Post: 05-13-2021, 02:31 PM
  2. Replies: 2
    Last Post: 06-23-2019, 03:30 PM
  3. 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
  4. Class Stuff: VBA Custom Classes & Objects, Class Modules
    By DocAElstein in forum Excel and VBA Tips and Tricks
    Replies: 17
    Last Post: 12-26-2018, 04:35 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
  •