Page 33 of 54 FirstFirst ... 23313233343543 ... LastLast
Results 321 to 330 of 604

Thread: Appendix-Thread-Evaluate-Range-(-Codes-for-other-Threads-HTML-Tables-etc-)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    lKSHFLhlhfl
    ….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. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    In support of this thread answer
    https://excelfox.com/forum/showthrea...rt-Csv-To-Xlsx

    Code:
    ' https://excelfox.com/forum/showthread.php/2519-Convert-Csv-To-Xlsx
    'XLFlNme is the Excel File name wanted for the new File
    'TxtFlNme is Text File name of an existing text file
    'valSep is the values separator used in the existing text file
    'LineSep is the line separator used in thee existing text file
    'Paf it the path to the files. ( I assume they are at the same place for the existing text file and the new Excel File )
    
    Function MakeXLFileusingvaluesInTextFile(ByVal Paf As String, ByVal TxtFlNme As String, ByVal XLFlNme As String, ByVal valSep As String, ByVal LineSep As String)
    
    Rem 2 Text file info
    ' 2a) get the text file as a long single string
    Dim FileNum As Long: Let FileNum = FreeFile(1)                                  ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
    Dim PathAndFileName As String, TotalFile As String
     Let PathAndFileName = Paf & Application.PathSeparator & TxtFlNme   '                                                               CHANGE TO SUIT                                                                                                         From vixer zyxw1234  : http://www.eileenslounge.com/viewtopic.php?f=30&t=34629     DF.txt https://app.box.com/s/gw941dh9v8sqhvzin3lo9rfc67fjsbic
    Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundemental type data input...
    TotalFile = Space(LOF(FileNum)) '....and wot recives it has to be a string of exactly the right length
    Get #FileNum, , TotalFile
    Close #FileNum
    ' 2b) Split into wholes line _ splitting the text file into rows by splitting by Line Seperator
    Dim arrRws() As String: Let arrRws() = Split(TotalFile, LineSep, -1, vbBinaryCompare)
    Dim RwCnt As Long: Let RwCnt = UBound(arrRws()) + 1    '  +1 is nedeed as the  Split Function  returns indicies 0 1 2 3 4 5   etc...
    ' 2c) split first line to determine the Field(column) number
    Dim arrClms() As String: Let arrClms() = Split(arrRws(0), valSep, -1, vbBinaryCompare)
    Dim ClmCnt As Long: Let ClmCnt = UBound(arrClms()) + 1
    ' 2d) we can now make an array for all the rows, and  columns 
    Dim arrOut() As String: ReDim arrOut(1 To RwCnt, 1 To ClmCnt)
    
    Rem 3 An array is built up by _....
    Dim Cnt As Long
        For Cnt = 1 To RwCnt '               _.. considering each row of data
        'Dim arrClms() As String
         Let arrClms() = Split(arrRws(Cnt - 1), ",", -1, vbBinaryCompare)  '  ___.. splitting each row into columns by splitting by the comma
        Dim Clm As Long   '
            For Clm = 1 To UBound(arrClms()) + 1
             Let arrOut(Cnt, Clm) = arrClms(Clm - 1)
            Next Clm
        Next Cnt
    
    Rem 4  Finally the array is pasted to a worksheet in a new file
     Workbooks.Add
     ActiveWorkbook.SaveAs Filename:=Paf & Application.PathSeparator & XLFlNme, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
     Workbooks("" & XLFlNme & "").Worksheets.Item(1).Range("A1").Resize(RwCnt, ClmCnt).Value = arrOut()
    
    End Function
    ….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!!

  3. #3
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    In support of the answer to these forum Thread posts
    https://www.excelforum.com/excel-pro...een-files.html
    https://excelfox.com/forum/showthrea...ll=1#post14130


    Code:
    '   https://www.excelforum.com/excel-programming-vba-macros/1319768-if-condition-met-then-put-the-remark-between-files.html#post5353174
    Sub karmapala()
    'Dim arr() As Variant
    Dim Wb1 As Workbook, Wb2 As Workbook, Sh1 As Worksheet, Sh2 As Worksheet
    Set Wb1 = Workbooks("1.xls")
    Set Sh1 = Wb1.Worksheets.Item(1)  ' Wb1.Sheets("1-Sheet1")
    Dim Rng As Range ' For main data range in 1.xls
    ' Set Rng = Sh1.Range("D2", Sh1.Range("D" & Rows.Count).End(xlUp)) ' This and the next line will error if macro.xlsm is active when the macro is run as Rows.Count will give a much larger number ( 1048576 ) than there are rows in a pre Excel 2007 worksheet ( .
    ' Set Rng = Sh1.Range(Sh1.Range("D2"), Sh1.Range("D" & Rows.Count).End(xlUp))'
    Set Rng = Sh1.Range("D2", Sh1.Range("D" & Sh1.Rows.Count).End(xlUp))
    Set Wb2 = Workbooks("macro.xlsm") ' Workbooks("Macro.xlsm")
    Set Sh2 = Wb2.Worksheets.Item(1)  ' Wb2.Sheets("Sheet1")
    Dim X As Long
    X = 0
    Rem 2 In this section we build an array, arr(),  of column I values to be                                               ...   match Column I of 1.xls with column B of macro.xlsm
    Dim Cel As Range
        For Each Cel In Rng
        Dim arr() As Variant ' This will become the array of column I values to be                                          ...   match Column I of 1.xls with column B of macro.xlsm
            If Cel.Value = Cel.Offset(0, 1).Value And Cel.Value <> Cel.Offset(0, 2).Value Then
            ' If column D of 1.xls is equal to Column E of 1.xls & column D of 1.xls is not equal to column F of 1.xls Then ...
            ReDim Preserve arr(X)
            arr(X) = Cel.Offset(0, 5) ' This is the column I value for                                                      ... match Column I of 1.xls with column B of macro.xlsm
            X = X + 1 ' to make the array element for the next entry, should there be one
            End If
    
            'If Cel.Value <> Cel.Offset(0, 1) And Cel.Value = Cel.Offset(0, 2) Then
            If Cel.Value = Cel.Offset(0, 2) And Cel.Value <> Cel.Offset(0, 1) Then   '                                      ...
            ReDim Preserve arr(X)
            ReDim Preserve arr(X)
            arr(X) = Cel.Offset(0, 5) ' This is the column I value for                                                      ... match Column I of 1.xls with column B of macro.xlsm
            X = X + 1 ' to make the array element for the next entry, should there be one
            End If
        Next
    
        If X = 0 Then Exit Sub
    
    Rem 3 In this section we take each of the values in column I of 1.xls meeting the criteria -                             ... match Column I of 1.xls with column B of macro.xlsm
    Dim El
        For Each El In arr() ' arr            take each value in column I meeting the criteria - and look for the match in a row in                           column B of macro.xlsm
        Dim B As Range ' The matched cell in column B in macro.xlsm
        Set B = Sh2.Range("B:B").Find(El, lookat:=xlWhole) ' Look for the       matched cell in macro.xlsm
            If Not B Is Nothing Then
            Dim FirstAddress As String: FirstAddress = B.Address ' The first match address to check when the  VBA .Find Methos starts again
                Do
                    If B.Offset(0, 1).Value = "" Then
                    B.Offset(0, 1).Value = 1 ' row of match has remark 1 in column C
                    Else
                    B.End(xlToRight).Offset(0, 1).Value = B.End(xlToRight).Value + 1
                    End If
                 Set B = Sh2.Range("B:B").FindNext(B)     ' Look for the  Next  matched cell in macro.xlsm
                Loop While B.Address <> FirstAddress          '  check when the  VBA .Find Methos starts again
            End If
        Next
    
    End Sub
    ….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!!

  4. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    post to get the URL - for later use
    ….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!!

  5. #5
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    post to get the URL - for later use
    ….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!!

  6. #6
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Solution1 fo this Thread
    http://www.eileenslounge.com/viewtop...270792#p270792

    Code:
    Sub VBAArrayTypeAlternativeToFilterInSegs_Solution1()  '     http://www.eileenslounge.com/viewtopic.php?p=270915#p270915               .......... https://eileenslounge.com/viewtopic.php?p=245238#p245238
    Rem Make the two row indicie lists ( string of row indicies seperated witha space )
    Dim arrK() As Variant: Let arrK() = Worksheets("Main workbook").Range("K1:K" & Worksheets("Main workbook").Range("A" & Rows.Count & "").End(xlUp).Row & "").Value
    Dim strSuc As String, strSpit As String
     Let strSuc = "7": Let strSpit = "7"
     Dim Cnt As Long
        For Cnt = 11 To UBound(arrK(), 1)
            If arrK(Cnt, 1) = "Positive" Then  '/////////
             Let strSuc = strSuc & " " & Cnt
            Else
             Let strSpit = strSpit & " " & Cnt
            End If
        Next Cnt
    'Debug.Print strSuc
    Rem Part A) modification (via string manipulation)
    Dim TotRws As Long: Let TotRws = (Len(strSuc) - Len(Replace(strSuc, " ", "", 1, -1, vbBinaryCompare))) + 1 ' effectively we are determining the number or spaces between the row indicies, then +1  to give us the number of row indicies
    Dim Segs As Long: Let Segs = Int(TotRws / 27) + 1
        For Cnt = 34 To ((Segs * 27) + ((Segs - 1) * 7) + 7) - 34 Step 34
         Let strSuc = Application.WorksheetFunction.Substitute(strSuc, " ", " 1 1 1 1 1 1 1 ", Cnt - 6) '           https://excelfox.com/forum/showthread.php/2230-Built-in-VBA-methods-and-functions-to-alter-the-contents-of-existing-character-strings
        Next Cnt
     Debug.Print strSuc
    Dim clms() As Variant: Let clms() = Array(1, 4, 6, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46)
    Dim strRws() As String: Let strRws() = Split(strSuc, " ", -1, vbBinaryCompare)
    Dim Rws() As String: ReDim Rws(1 To UBound(strRws(), 1) + 1, 1 To 1)
        For Cnt = 1 To UBound(strRws(), 1) + 1 ': Debug.Print strRws(Cnt - 1)
         Let Rws(Cnt, 1) = strRws(Cnt - 1)
        Next Cnt
    Dim arrOut() As Variant: Let arrOut() = Application.Index(Worksheets("Main workbook").Cells, Rws(), clms())
     Let Worksheets("consultant doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2)) = arrOut()
    ' =====================================================
    Rem Part B)
    ' Header
     Worksheets("TempSht").Range("A7:X7").Copy
     Worksheets("consultant doctor").Range("A7:X7").PasteSpecial Paste:=xlPasteAll    '     https://docs.microsoft.com/en-us/office/vba/api/excel.range.pastespecial       https://docs.microsoft.com/de-de/office/vba/api/excel.xlpastetype
    ' All formats in one go for each segmant from the temporary blue print worksheet
     Worksheets("TempSht").Range("A8:X41").Copy
     Worksheets("consultant doctor").Range("A8:X" & ((Segs * 27) + ((Segs - 1) * 7) + 7) + 1 & "").PasteSpecial Paste:=xlPasteFormats   '
    ' Formulas
      Worksheets("TempSht").Range("A35:X41").Copy
        For Cnt = 34 To ((Segs * 27) + ((Segs - 1) * 7) + 7) Step 34
         Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(1, 0).Resize(7, 24).PasteSpecial Paste:=xlFormulas '                  Value = Worksheets("TempSht").Range("A35:X41").Formula
    '     Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 0).Resize(7, 24).Sort key1:=Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 2), Header:=False   '   sorting here will clear the clipboard
        Next Cnt
    ' Sorting
        For Cnt = 34 To ((Segs * 27) + ((Segs - 1) * 7) + 7) Step 34
         Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 0).Resize(7, 24).Sort key1:=Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 2), Header:=False
        Next Cnt
    
    'With Worksheets("consultant doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2))
    '' Let .Value = arrOut()
    '.Sort key1:=Worksheets("consultant doctor").Range("C7"), Header:=True
    '.Font.Name = "Times New Roman"
    '.Font.Size = 13
    '.Columns("D:X").NumberFormat = "0.00"
    '.EntireColumn.AutoFit
    'End With
    
    ''Let clms() = Array(1, 4, 6, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46)
    ' Let strRws() = Split(strSpit, " ", -1, vbBinaryCompare)
    ' ReDim Rws(1 To UBound(strRws(), 1) + 1, 1 To 1)
    '    For Cnt = 1 To UBound(strRws(), 1) + 1
    '     Let Rws(Cnt, 1) = strRws(Cnt - 1)
    '    Next Cnt
    ' Let arrOut() = Application.Index(Worksheets("Main workbook").Cells, Rws(), clms())
    'With Worksheets("Specialist Doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2))
    'Let .Value = arrOut()
    ''.Sort Key1:=Worksheets("Specialist Doctor").Range("C7"), Header:=True
    '.Font.Name = "Times New Roman"
    '.Font.Size = 13
    '.Columns("D:X").NumberFormat = "0.00"
    '.EntireColumn.AutoFit
    'End With
    End Sub
    ….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!!

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

    Solution 2

    Solution for this post:
    https://eileenslounge.com/viewtopic....271047#p271047
    https://eileenslounge.com/viewtopic....271137#p271137

    The main thing is
    Sub DropItIn()

    The first macro, Sub VBAArrayTypeAlternativeToFilterToSegs_Solution2() , which is the one that you run, is almost identical to the very first unmodified macro, Sub VBAArrayTypeAlternativeToFilter() ' https://eileenslounge.com/viewtopic....270792#p270792



    Code:
    Sub VBAArrayTypeAlternativeToFilterToSegs_Solution2() '               https://eileenslounge.com/viewtopic.php?p=271047&sid=d23ea475322d2edf06b70bfeaa95726b#p271047
    ' Main Data worksheet
    Dim arrK() As Variant: Let arrK() = Worksheets("Main workbook").Range("K1:K" & Worksheets("Main workbook").Range("A" & Rows.Count & "").End(xlUp).Row & "").Value
    ' Get row indicies for the two output worksheets
    Dim strSuc As String, strSpit As String
    Let strSuc = "7": Let strSpit = "7"
    Dim Cnt As Long
        For Cnt = 11 To UBound(arrK(), 1)
            If arrK(Cnt, 1) = "Positive" Then  '/////////
             Let strSuc = strSuc & " " & Cnt
            Else
             Let strSpit = strSpit & " " & Cnt
            End If
        Next Cnt
    ' First output worksheet
    Dim clms() As Variant: Let clms() = Array(1, 4, 6, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46)
    Dim strRws() As String: Let strRws() = Split(strSuc, " ", -1, vbBinaryCompare)
    Dim Rws() As String: ReDim Rws(1 To UBound(strRws(), 1) + 1, 1 To 1)
        For Cnt = 1 To UBound(strRws(), 1) + 1
         Let Rws(Cnt, 1) = strRws(Cnt - 1)
        Next Cnt
    Dim arrOut() As Variant: Let arrOut() = Application.Index(Worksheets("Main workbook").Cells, Rws(), clms())
        With Worksheets("consultant doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2))
        Let .Value = arrOut()
        .Sort Key1:=Worksheets("consultant doctor").Range("C7"), Header:=True
        .Font.Name = "Times New Roman"
        .Font.Size = 13
        .Columns("D:X").NumberFormat = "0.00"
        .EntireColumn.AutoFit
        .Borders.LineStyle = xlContinuous
        End With
    ' Adding extra rows and stuff for  Worksheets("consultant doctor") ================
    '        Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
     Call DropItIn(Worksheets("consultant doctor"), UBound(strRws(), 1) + 1, 8, 34, 27, 7)                                            '  Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
    ' second output worksheet
    'Let clms() = Array(1, 4, 6, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46)
     Let strRws() = Split(strSpit, " ", -1, vbBinaryCompare)
     ReDim Rws(1 To UBound(strRws(), 1) + 1, 1 To 1)
        For Cnt = 1 To UBound(strRws(), 1) + 1
         Let Rws(Cnt, 1) = strRws(Cnt - 1)
        Next Cnt
     Let arrOut() = Application.Index(Worksheets("Main workbook").Cells, Rws(), clms())
        With Worksheets("Specialist Doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2))
         Let .Value = arrOut()
         .Sort Key1:=Worksheets("Specialist Doctor").Range("C7"), Header:=True
         .Font.Name = "Times New Roman"
         .Font.Size = 13
         .Columns("D:X").NumberFormat = "0.00"
         .EntireColumn.AutoFit
         .Borders.LineStyle = xlContinuous
        End With
    ' Adding extra rows and stuff for  Worksheets("Specialist Doctor") ==================
    '        Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
     Call DropItIn(Worksheets("Specialist Doctor"), UBound(strRws(), 1) + 1, 8, 34, 27, 7)                                            '  Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
    
    End Sub
    ….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. #8
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10

    Solution 3

    Macros for Solution 3 in this Thread here
    https://eileenslounge.com/viewtopic.php?f=30&t=34878
    Post
    https://eileenslounge.com/viewtopic....271150#p271150


    Code:
    Sub Solution3_2Workbooks() '
    Rem 1 Worksheets info
    Dim WbM As Workbook, WbData As Workbook
     Set WbM = ThisWorkbook: Set WbData = Workbooks("Example.xlsx")
    ' Main Data worksheet
    Dim arrK() As Variant: Let arrK() = WbData.Worksheets("Main workbook").Range("K1:K" & Worksheets("Main workbook").Range("A" & Rows.Count & "").End(xlUp).Row & "").Value
    ' Get row indicies for the two output worksheets
    Dim strSuc As String, strSpit As String
    Let strSuc = "7": Let strSpit = "7"
    Dim Cnt As Long
        For Cnt = 11 To UBound(arrK(), 1)
            If arrK(Cnt, 1) = "Positive" Then  '/////////
             Let strSuc = strSuc & " " & Cnt
            Else
             Let strSpit = strSpit & " " & Cnt
            End If
        Next Cnt
    ' First output worksheet
    Dim clms() As Variant: Let clms() = Array(1, 4, 6, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46)
    Dim strRws() As String: Let strRws() = Split(strSuc, " ", -1, vbBinaryCompare)
    Dim Rws() As String: ReDim Rws(1 To UBound(strRws(), 1) + 1, 1 To 1)
        For Cnt = 1 To UBound(strRws(), 1) + 1
         Let Rws(Cnt, 1) = strRws(Cnt - 1)
        Next Cnt
    Dim arrOut() As Variant: Let arrOut() = Application.Index(Worksheets("Main workbook").Cells, Rws(), clms())
        With WbData.Worksheets("consultant doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2))
        Let .Value = arrOut()
        .Sort Key1:=Worksheets("consultant doctor").Range("C7"), Header:=True
        .Font.Name = "Times New Roman"
        .Font.Size = 13
        .Columns("D:X").NumberFormat = "0.00"
        .EntireColumn.AutoFit
        .Borders.LineStyle = xlContinuous
        End With
    ' Adding extra rows and stuff for  Worksheets("consultant doctor") ================
    '        Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
     Call DropItIn3(WbData.Worksheets("consultant doctor"), UBound(strRws(), 1) + 1, 8, 34, 27, 7)                                            '  Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
    ' second output worksheet
    'Let clms() = Array(1, 4, 6, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46)
     Let strRws() = Split(strSpit, " ", -1, vbBinaryCompare)
     ReDim Rws(1 To UBound(strRws(), 1) + 1, 1 To 1)
        For Cnt = 1 To UBound(strRws(), 1) + 1
         Let Rws(Cnt, 1) = strRws(Cnt - 1)
        Next Cnt
     Let arrOut() = Application.Index(Worksheets("Main workbook").Cells, Rws(), clms())
        With WbData.Worksheets("Specialist Doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2))
         Let .Value = arrOut()
         .Sort Key1:=Worksheets("Specialist Doctor").Range("C7"), Header:=True
         .Font.Name = "Times New Roman"
         .Font.Size = 13
         .Columns("D:X").NumberFormat = "0.00"
         .EntireColumn.AutoFit
         .Borders.LineStyle = xlContinuous
        End With
    ' Adding extra rows and stuff for  Worksheets("Specialist Doctor") ==================
    '        Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
     Call DropItIn3(WbData.Worksheets("Specialist Doctor"), UBound(strRws(), 1) + 1, 8, 34, 27, 7)                                            '  Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
    
    End Sub
    
    
    
    '  Call '  Worksheet,data row count, First data row, First break in data, data rows, extra rows to be inserted
    'Worksheets("consultant doctor"), UBound(strRws(), 1) + 1 ,    8    ,   34      27,     7
    '                                     88    ,       8      ,         34     ,     27        ,    7
    Sub DropItIn3(Ws As Worksheet, RwsCnt As Long, SttRw As Long, FstBkRw As Long, DtaRws As Long, ExtRws As Long)    '      https://eileenslounge.com/viewtopic.php?p=271047&sid=d23ea475322d2edf06b70bfeaa95726b#p271047
    ' Header
     ThisWorkbook.Worksheets("TempSht").Range("A7:X7").Copy
     Ws.Range("A" & SttRw - 1 & ":X" & SttRw - 1 & "").PasteSpecial Paste:=xlPasteFormats  '     https://docs.microsoft.com/en-us/office/vba/api/excel.range.pastespecial       https://docs.microsoft.com/de-de/office/vba/api/excel.xlpastetype
    ' Insert extra rows
    '  Worksheets("TempSht").Range("A35:X41").Copy
    Dim Cnt As Long
    '    For Cnt = FstBkRw To ((((Int(RwsCnt / DtaRws) + 1) * DtaRws) + (((Int(RwsCnt / DtaRws) + 1) - 1) * ExtRws) + (SttRw - 1))) - (DtaRws + ExtRws) Step DtaRws + ExtRws  '  This misses the last section
        For Cnt = FstBkRw To ((((Int(RwsCnt / DtaRws) + 1) * DtaRws) + (((Int(RwsCnt / DtaRws) + 1) - 1) * ExtRws) + (SttRw - 1))) Step DtaRws + ExtRws
         ThisWorkbook.Worksheets("TempSht").Range("A35:X41").Copy
         Ws.Range("A" & Cnt & "").Offset(1, 0).Resize(7, 24).Insert shift:=xlShiftDown '                  Value = Worksheets("TempSht").Range("A35:X41").Formula
    '     Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 0).Resize(7, 24).Sort key1:=Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 2), Header:=False   '   sorting here will clear the clipboard
        Next Cnt
    
    End Sub
    ….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!!

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

    Solution 4

    Macro for solution 4 for this Thread here
    https://eileenslounge.com/viewtopic.php?f=30&t=34878
    Post
    https://eileenslounge.com/viewtopic....5c9974#p271181

    Code:
    Sub VBAArrayTypeAlternativeToFilterSolution4()  '                                                       BY M. Doc.AElstein .......... https://eileenslounge.com/viewtopic.php?p=245238#p245238
    ' Main Data worksheet
    Dim arrK() As Variant: Let arrK() = Worksheets("Main workbook").Range("K1:K" & Worksheets("Main workbook").Range("A" & Rows.Count & "").End(xlUp).Row & "").Value
    ' Get row indicies for the two output worksheets
    Dim strSuc As String, strSpit As String
    Let strSuc = "7": Let strSpit = "7"
    Dim Cnt As Long
        For Cnt = 11 To UBound(arrK(), 1)
            If arrK(Cnt, 1) = "Positive" Then  '/////////
             Let strSuc = strSuc & " " & Cnt
            Else
             Let strSpit = strSpit & " " & Cnt
            End If
        Next Cnt
    Debug.Print strSuc
    ' First output worksheet
    Dim Clms() As Variant: Let Clms() = Array(1, 4, 6, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46)
    Dim strRws() As String: Let strRws() = Split(strSuc, " ", -1, vbBinaryCompare)
    ' sorting with Arrays
    Dim strNms() As Variant ' this will be the array of names in the order corresponding to the strRws() indicies
     Let strNms() = Application.Index(Worksheets("Main workbook").Cells, strRws(), 6)
    ' Array sort of Bubble sort, sort of
    Dim rOuter As Long ' ========"Left Hand"=========================Outer Loop=====================================
        For rOuter = 2 To UBound(strNms)
        Dim rInner As Long ' -------Inner Loop-------------"Right Hand"--------------------------
            For rInner = rOuter + 1 To UBound(strNms) ' from just above left hand through all the rest
                If strNms(rOuter) > strNms(rInner) Then
                Dim varTemp As Variant ' I want to Swap those 2 above ( and the corresponding strRws() ) - I cant easilly in any coding change two values simulataneosly. So one of them Element values will put in this temporary place. This Element Values will then be given the other. Finally the other Element will be given this temporary value
                 Let varTemp = strNms(rOuter): Let strNms(rOuter) = strNms(rInner): Let strNms(rInner) = varTemp
                Dim TempRs As String
                 Let TempRs = strRws(rOuter - 1): Let strRws(rOuter - 1) = strRws(rInner - 1): Let strRws(rInner - 1) = TempRs ' the -1 is because strRws() starts at 0  not 1
                Else
                End If
            Next rInner ' -----------------------------------------------------------------------
        Next rOuter ' ==================End  Outer Loop===============================================================
    ' we must now re make strsuc
     Let strSuc = Join(strRws(), " ")
    Rem Part A) modification (via string manipulation)
    Dim TotRws As Long: Let TotRws = (Len(strSuc) - Len(Replace(strSuc, " ", "", 1, -1, vbBinaryCompare))) + 1 ' effectively we are determining the number or spaces between the row indicies, then +1  to give us the number of row indicies
    Dim Segs As Long: Let Segs = Int(TotRws / 27) + 1
        For Cnt = 34 To ((Segs * 27) + ((Segs - 1) * 7) + 7) - 34 Step 34
         Let strSuc = Application.WorksheetFunction.Substitute(strSuc, " ", " 1 1 1 1 1 1 1 ", Cnt - 6) '           https://excelfox.com/forum/showthread.php/2230-Built-in-VBA-methods-and-functions-to-alter-the-contents-of-existing-character-strings
        Next Cnt
     Let strRws() = Split(strSuc, " ", -1, vbBinaryCompare)
    Dim Rws() As String: ReDim Rws(1 To UBound(strRws(), 1) + 1, 1 To 1)
        For Cnt = 1 To UBound(strRws(), 1) + 1
         Let Rws(Cnt, 1) = strRws(Cnt - 1)
        Next Cnt
    Dim arrOut() As Variant
     Let arrOut() = Application.Index(Worksheets("Main workbook").Cells, Rws(), Clms())
     Let Worksheets("consultant doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2)) = arrOut()
    Rem Part B)
    ' Header
     Worksheets("TempSht").Range("A7:X7").Copy
     Worksheets("consultant doctor").Range("A7:X7").PasteSpecial Paste:=xlPasteAll    '     https://docs.microsoft.com/en-us/office/vba/api/excel.range.pastespecial       https://docs.microsoft.com/de-de/office/vba/api/excel.xlpastetype
    ' All formats in one go for each segmant from the temporary blue print worksheet
     Worksheets("TempSht").Range("A8:X41").Copy
     Worksheets("consultant doctor").Range("A8:X" & ((Segs * 27) + ((Segs - 1) * 7) + 7) + 1 & "").PasteSpecial Paste:=xlPasteFormats   '
    ' Formulas
      Worksheets("TempSht").Range("A35:X41").Copy
        For Cnt = 34 To ((Segs * 27) + ((Segs - 1) * 7) + 7) Step 34
         Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(1, 0).Resize(7, 24).PasteSpecial Paste:=xlFormulas '                  Value = Worksheets("TempSht").Range("A35:X41").Formula
    '     Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 0).Resize(7, 24).Sort key1:=Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 2), Header:=False   '   sorting here will clear the clipboard
        Next Cnt
    ''' Sorting  NO LONGER NEEDED
    ''    For Cnt = 34 To ((Segs * 27) + ((Segs - 1) * 7) + 7) Step 34
    ''     Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 0).Resize(7, 24).Sort key1:=Worksheets("consultant doctor").Range("A" & Cnt & "").Offset(-26, 2), Header:=False
    ''    Next Cnt
    
    '    With Worksheets("consultant doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2))
    '    Let .Value = arrOut()
    '    .Sort Key1:=Worksheets("consultant doctor").Range("C7"), Header:=True
    '    .Font.Name = "Times New Roman"
    '    .Font.Size = 13
    '    .Columns("D:X").NumberFormat = "0.00"
    '    .EntireColumn.AutoFit
    '    End With
    '' second output worksheet
    ''Let clms() = Array(1, 4, 6, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46)
    'Let strRws() = Split(strSpit, " ", -1, vbBinaryCompare)
    'ReDim Rws(1 To UBound(strRws(), 1) + 1, 1 To 1)
    '    For Cnt = 1 To UBound(strRws(), 1) + 1
    '     Let Rws(Cnt, 1) = strRws(Cnt - 1)
    '    Next Cnt
    ' Let arrOut() = Application.Index(Worksheets("Main workbook").Cells, Rws(), Clms())
    '    With Worksheets("Specialist Doctor").Range("A7").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2))
    '     Let .Value = arrOut()
    '     .Sort Key1:=Worksheets("Specialist Doctor").Range("C7"), Header:=True
    '     .Font.Name = "Times New Roman"
    '     .Font.Size = 13
    '     .Columns("D:X").NumberFormat = "0.00"
    '     .EntireColumn.AutoFit
    '    End With
    End Sub
    
    
    ….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. #10
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Macro solution for this post:
    https://excelfox.com/forum/showthrea...ther-workbooks

    Code:
    '  https://excelfox.com/forum/showthread.php/2569-Copy-row-from-one-workbook-to-another-workbook-based-on-conditions-in-two-other-workbooks
    '   Copy row from one workbook to another workbook  based on conditions in two other workbooks
    Sub CopyRowFromWb4ToWb3basedOnConditionsInWb1AndWb2()
    Rem 1 worksheets range info
    Dim Wb1 As Workbook, Wb2 As Workbook, Wb3 As Workbook, Wb4 As Workbook
     Set Wb1 = Workbooks("1.xls")
     Set Wb2 = Workbooks("ap.xls")
     Set Wb3 = Workbooks("BasketOrder.xlsx")
     Set Wb4 = Workbooks("OrderFormat.xlsx")
    Dim Ws1 As Worksheet, Ws2 As Worksheet, Ws3 As Worksheet, Ws4 As Worksheet
     Set Ws1 = Wb1.Worksheets.Item(1)
     Set Ws2 = Wb2.Worksheets.Item(1)
     Set Ws3 = Wb3.Worksheets.Item(1)
     Set Ws4 = Wb4.Worksheets.Item(1)
    Dim Lr1 As Long, Lr2 As Long, Lr3 As Long ', Lr4 As Long
     Let Lr1 = Ws1.Range("A" & Ws1.Rows.Count & "").End(xlUp).Row
     Let Lr2 = Ws2.Range("D" & Ws2.Rows.Count & "").End(xlUp).Row
    Dim Rng1 As Range, Rng2 As Range ', Rng3 As Range, Rng4 As Range
     Set Rng1 = Ws1.Range("A1:I" & Lr1 & "")
     Set Rng2 = Ws2.Range("A1:Z" & Lr2 & "")
    '1b) data ranges for conditions
    Dim arr1() As Variant: Let arr1() = Rng1.Value2
    Dim arr1I() As Variant: Let arr1I() = Rng1.Columns(9).Value2
    Dim arr2() As Variant: Let arr2() = Rng2.Value2
    Dim arr2Z() As Variant: Let arr2Z() = Rng2.Columns("Z").Value2
    Rem 2 Do it
    Dim Cnt
        For Cnt = 2 To Lr1 Step 1
            If arr1I(Cnt, 1) <> "" Then
            Dim MtchRes As Variant
             Let MtchRes = Application.Match(arr1I(Cnt, 1), arr2Z(), 0)
                If IsError(MtchRes) Then
                ' column I 1.xls value is not in column Z of ap.xls
                Else '  column I of 1.xls matches with column Z of ap.xls
                    ' if column K of ap.xls is equals to column L of ap.xls
                    If arr2(MtchRes, 11) = arr2(MtchRes, 12) Then
                    ' If column H of 1.xls is greater than column D of 1.xls then
                        If arr1(Cnt, 8) > arr1(Cnt, 4) Then
                        'copy the first row of OrderFormat.xlsx & paste it to BasketOrder.xlsx
                         Let Ws3.Range("A1:U1").Value2 = Ws4.Range("A1:U1").Value2
                        ElseIf arr1(Cnt, 8) < arr1(Cnt, 4) Then ' If column H of 1.xls is less than column D of 1.xls then
                        'copy the third row of OrderFormat.xlsx & pate it to BasketOrder.xlsx
                        Else
                         Let Ws3.Range("A1:U1").Value2 = Ws4.Range("A3:U3").Value2
                        End If
                    Else
                    ' column K of ap.xls is not equal to column L of ap.xls
                    End If
                End If
            Else
            ' empty column I in 1.xls
            End If
        Next Cnt
    End Sub
    
    ….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!!

Similar Threads

  1. Testing Concatenating with styles
    By DocAElstein in forum Test Area
    Replies: 2
    Last Post: 12-20-2020, 02:49 AM
  2. testing
    By Jewano in forum Test Area
    Replies: 7
    Last Post: 12-05-2020, 03:31 AM
  3. Replies: 18
    Last Post: 03-17-2019, 06:10 PM
  4. Concatenating your Balls
    By DocAElstein in forum Excel Help
    Replies: 26
    Last Post: 10-13-2014, 02:07 PM
  5. Replies: 1
    Last Post: 12-04-2012, 08:56 AM

Posting Permissions

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