Page 17 of 22 FirstFirst ... 71516171819 ... LastLast
Results 161 to 170 of 214

Thread: YouTube, Video making and editing, etc. coupled to excelfox ( windows Movie Maker )

  1. #161
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,522
    Rep Power
    10
    Run Code Sub ExportByName() on data from last post

    Results for Updated master Worksheet

    Using Excel 2007 32 bit
    Row\Col
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    25
    24
    ABC24
    $ 3.99
    35
    $ 139.65
    02.Apr.2018 MT1 MT2 MT3 MT4 02.Apr.2018 02.Apr.2018 Margaret
    26
    25
    ABC25
    $ 333.45
    99
    $ 33,011.55
    02.Apr.2018 Raghu
    27
    26
    ABC26
    $ 11.99
    1
    $ 11.99
    02.Apr.2018 John
    28
    27
    ABC27
    $ 741.99
    101
    $ 74,940.99
    02.Apr.2018 Greg
    29
    28
    ABC28
    $ 55.00
    22
    $ 1,210.00
    02.Apr.2018 MT1 MT2 MT3 MT4 02.Apr.2018 02.Apr.2018 Margaret
    30
    29
    ABC29
    $ 13.66
    7
    $ 95.62
    02.Apr.2018 Raghu
    31
    30
    ABC30
    $ 12.99
    5
    $ 64.95
    02.Apr.2018 John
    32
    31
    ABC31
    $ 8.51
    12
    $ 102.12
    02.Apr.2018 Greg
    33
    32
    ABC32
    $ 7.22
    62
    $ 447.64
    02.Apr.2018 Margaret
    34
    33
    ABC33
    $ 3.99
    35
    $ 139.65
    02.Apr.2018 Raghu
    35
    34
    ABC34
    $ 333.45
    99
    $ 33,011.55
    02.Apr.2018 John
    36
    35
    ABC35
    $ 11.99
    1
    $ 11.99
    02.Apr.2018 Greg
    37
    36
    ABC36
    $ 741.99
    101
    $ 74,940.99
    02.Apr.2018 Margaret
    38
    37
    ABC37
    $ 55.00
    22
    $ 1,210.00
    02.Apr.2018 Raghu
    39
    38
    ABC38
    $ 13.66
    7
    $ 95.62
    02.Apr.2018 John
    40
    39
    ABC39
    $ 12.99
    5
    $ 64.95
    02.Apr.2018 Greg
    41
    40
    ABC40
    $ 8.51
    12
    $ 102.12
    02.Apr.2018 Margaret
    42
    41
    ABC41
    $ 7.22
    62
    $ 447.64
    02.Apr.2018 Raghu
    43
    42
    ABC42
    $ 3.99
    35
    $ 139.65
    02.Apr.2018 John
    44
    43
    ABC43
    $ 333.45
    99
    $ 33,011.55
    02.Apr.2018 Greg
    45
    44
    ABC44
    $ 11.99
    1
    $ 11.99
    02.Apr.2018 Margaret
    46
    45
    ABC45
    $ 741.99
    101
    $ 74,940.99
    02.Apr.2018 Raghu
    47
    46
    ABC46
    $ 8.51
    12
    $ 102.12
    02.Apr.2018
    John
    48
    47
    ABC47
    $ 7.22
    62
    $ 447.64
    02.Apr.2018
    Greg
    49
    48
    ABC48
    $ 3.99
    35
    $ 139.65
    02.Apr.2018
    Margaret
    50
    49
    ABC49
    $ 333.45
    99
    $ 33,011.55
    02.Apr.2018
    Raghu
    51
    50
    ABC50
    $ 11.99
    1
    $ 11.99
    02.Apr.2018
    Raghu
    52
    53
    54
    Worksheet: OriginalData

  2. #162
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,522
    Rep Power
    10
    Corresponding updated data worksheets for updated master after running Sub ExportByName() for the second time after new data was added

    Using Excel 2007 32 bit
    41
    ABC41
    $ 7.22
    62
    $ 447.64
    02.Apr.2018 Raghu
    45
    ABC45
    $ 741.99
    101
    $ 74,940.99
    02.Apr.2018 Raghu
    49
    ABC49 $ 333.45
    99
    $ 33,011.55 02.Apr.2018 Raghu
    50
    ABC50 $ 11.99
    1
    $ 11.99 02.Apr.2018 Raghu
    Worksheet: Tabelle1





    Using Excel 2007 32 bit
    40
    ABC40
    $ 8.51
    12
    $ 102.12
    02.Apr.2018 Margaret
    44
    ABC44
    $ 11.99
    1
    $ 11.99
    02.Apr.2018 Margaret
    48
    ABC48 $ 3.99
    35
    $ 139.65 02.Apr.2018 Margaret
    Worksheet: Tabelle1



    Using Excel 2007 32 bit
    38
    ABC38
    $ 13.66
    7
    $ 95.62
    02.Apr.2018 John
    42
    ABC42
    $ 3.99
    35
    $ 139.65
    02.Apr.2018 John
    46
    ABC46 $ 8.51
    12
    $ 102.12 02.Apr.2018 John
    Worksheet: Tabelle1



    Using Excel 2007 32 bit
    39
    ABC39
    $ 12.99
    5
    $ 64.95
    02.Apr.2018 Greg
    43
    ABC43
    $ 333.45
    99
    $ 33,011.55
    02.Apr.2018 Greg
    47
    ABC47 $ 7.22
    62
    $ 447.64 02.Apr.2018 Greg
    Worksheet: Tabelle1

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

    Summary of info in the XML files for "ClsdData.xls” and "NameObjectFile.xls”

    Summary of info in the XML files for "ClsdData.xls" and "NameObjectFile.xls"


    app.xml
    "ClsdData.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    <Properties xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"><TotalTime>0</TotalTime><Application>Microsoft Excel</Application><DocSecurity>0</DocSecurity><ScaleCrop>false</ScaleCrop><HeadingPairs><vt:vector baseType="variant" size="4"><vt:variant><vt:lpstr>Arbeitsblätter</vt:lpstr></vt:variant><vt:variant><vt:i4>1</vt:i4></vt:variant><vt:variant><vt:lpstr>Benannte Bereiche</vt:lpstr></vt:variant><vt:variant><vt:i4>2</vt:i4></vt:variant></vt:vector></HeadingPairs><TitlesOfParts><vt:vector baseType="lpstr" size="3"><vt:lpstr>DataSht_1</vt:lpstr><vt:lpstr>DataSht_1!NameForDataSht_1A1</vt:lpstr><vt:lpstr>DataSht_1!Sht_1A1</vt:lpstr></vt:vector></TitlesOfParts><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>12.0000</AppVersion></Properties>

    "NameObjectFile.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    <Properties xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"><TotalTime>0</TotalTime><Application>Microsoft Excel</Application><DocSecurity>0</DocSecurity><ScaleCrop>false</ScaleCrop><HeadingPairs><vt:vector baseType="variant" size="2"><vt:variant><vt:lpstr>Arbeitsblätter</vt:lpstr></vt:variant><vt:variant><vt:i4>1</vt:i4></vt:variant></vt:vector></HeadingPairs><TitlesOfParts><vt:vector baseType="lpstr" size="1"><vt:lpstr>NameObjectsSht_1</vt:lpstr></vt:vector></TitlesOfParts><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>12.0000</AppVersion></Properties>

    _.________________________________________________ _________________

    sharedStrings.XML
    "ClsdData.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    -<sst uniqueCount="2" count="2" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">-<si><t>dataA1</t></si>-<si><t>dataB1</t></si></sst>

    "NameObjectFile.xls"
    -
    _.________________________________________________ _____________________

    workbook.xml
    "ClsdData.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    <workbook xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fileVersion rupBuild="4507" lowestEdited="4" lastEdited="4" appName="xl"/><workbookPr defaultThemeVersion="124226" codeName="DieseArbeitsmappe"/><bookViews><workbookView windowHeight="11535" windowWidth="14910" yWindow="30" xWindow="240"/></bookViews><sheets><sheet r:id="rId1" sheetId="1" name="DataSht_1"/></sheets><definedNames><definedName name="NameForDataSht_1A1" localSheetId="0">DataSht_1!$A$1</definedName><definedName name="Sht_1A1" localSheetId="0">DataSht_1!$A$1</definedName></definedNames><calcPr calcId="125725"/></workbook>

    "NameObjectFile.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    <workbook xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fileVersion rupBuild="4507" lowestEdited="4" lastEdited="4" appName="xl"/><workbookPr defaultThemeVersion="124226" codeName="DieseArbeitsmappe"/><bookViews><workbookView windowHeight="11535" windowWidth="14910" yWindow="30" xWindow="240"/></bookViews><sheets><sheet r:id="rId1" sheetId="1" name="NameObjectsSht_1"/></sheets><externalReferences><externalReference r:id="rId2"/></externalReferences><definedNames><definedName name="NameForDataSht_1B1" localSheetId="0">[1]DataSht_1!$B$1</definedName></definedNames><calcPr calcId="125725"/></workbook>


    _.________________________________________________ __________________________________________

    sheet1.XML
    "ClsdData.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    <worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetPr codeName="Tabelle1"/><dimension ref="A1:B1"/><sheetViews><sheetView workbookViewId="0" tabSelected="1"><selection sqref="B8" activeCell="B8"/></sheetView></sheetViews><sheetFormatPr defaultRowHeight="12" baseColWidth="10"/><sheetData><row r="1" spans="1:2"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c></row></sheetData><pageMargins footer="0.3" header="0.3" bottom="0.78740157499999996" top="0.78740157499999996" right="0.7" left="0.7"/></worksheet>


    "NameObjectFile.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    <worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetPr codeName="Tabelle1"/><dimension ref="A1"/><sheetViews><sheetView workbookViewId="0" tabSelected="1"/></sheetViews><sheetFormatPr defaultRowHeight="12" baseColWidth="10"/><sheetData/><pageMargins footer="0.3" header="0.3" bottom="0.78740157499999996" top="0.78740157499999996" right="0.7" left="0.7"/></worksheet>


    _.________________________________________________ _______
    Workbook.XML.rels
    "ClsdData.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Id="rId3"/><Relationship Target="theme/theme1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Id="rId2"/><Relationship Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId1"/><Relationship Target="sharedStrings.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Id="rId4"/></Relationships>

    "NameObjectFile.xls"
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Target="theme/theme1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Id="rId3"/><Relationship Target="externalLinks/externalLink1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink" Id="rId2"/><Relationship Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId1"/><Relationship Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Id="rId4"/></Relationships>

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

    A brief introduction to objects and class objects in VBA

    Some notes to support other posts: A brief introduction to objects and class objects in VBA

    This is to support a Tips and Tutorial on advanced Event coding. ( http://www.excelfox.com/forum/showth...ication-Events ) It is difficult to look at advanced events coding without hitting some fundamental ideas behind objects and class objects in VBA.

    This thing, “Tabelle2” , ( https://imgur.com/hHHdxyD ) .._
    Attachment 2114 , _.. could loosely be described as a "“worksheet” object with a code in it"…
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$A$1" Then MsgBox prompt:="You just changed the value in the first cell in worksheet " & Me.Name & " in the Workbook " & Me.Parent.Name
    End Sub
    Right mouse click Or double click in VBA explorer Project window to get code module.JPG : https://imgur.com/gsz6s2N
    That coding results in you getting a simple message if you change the value in the first worksheet cell :
    Automatic message after change value in first cell .JPG : https://imgur.com/WFINlbq , https://imgur.com/hHHdxyD

    _ The actual object: where what how to get at or change
    _ what precisely/ physically any object is, is not precisely defined. Consequently what we actually use, and where, in order to “use” an object is somewhat abstract and can be different at different times or for different purposes. As example, In the code example above we were using the second worksheet in a workbook. That worksheet object could “physically” be described as the spreadsheet we “see” when clicking on the second tab. Writing into cells could be described as using the worksheet object. But you will see that in the simple routine above, we referred to the second worksheet object using “.Me” ( Me.JPG : https://imgur.com/R5nJ4n9 ). This is because the code module and code window shown in the screenshots above is also often considered to be that worksheet object. This should confuse you. The concept is not precise. I think possibly in the last 20 years there were too many people employed in the computer industry who had nothing to do. They may have gone a bit mad in their boredom.

    _ Class. Class object
    _ If we “go back up” the programming hierarchy from, say a worksheet, then we would often have a class object which could / is sometimes seen as actually physically being a Class code module. So that would be a code module similar “looking” to our worksheet code module, but placed somewhere further “up” the hierarchy. A “Class” in VBA is as vague a concept as most VBA stuff follows the word definition of something along the lines of a blueprint or template or Type.
    One could thing of the Class as the instructions, as simple text , on how to build something, and a VBA object could be built following those instructions.
    A Variable used for an object will generally need to be declared ( Dimed ) to a specific type, and early on in VBA programming one may have, unknowingly, used a Class without realising it, for example , in code lines like these , the word Range , refers to the class Range
    Dim Rng As Range
    _ Set Rng=Range(“A1”)

    In general, any object will be of a certain type , and the coding or information needed to use those objects will to a large extent be contained in its class. This may or may not be “see able” or accessible to us: it may or may not have a class code module. Such a code module, if it exists, can , and often is, loosely define as that Class object and which we then may or may not be able to access, see and/ or change:…
    Class Class object WorksheetType2.JPG : https://imgur.com/PPUfc2w
    Class Class object.JPG : https://imgur.com/3WDRcpU

    It is very confusing to try and get a clear picture of this structure in the VBA Project window because Microsoft Excel and Microsoft Excel VBA is a disorganised mess:
    On the one hand: We see in the VB Editor VBA Project window the individual worksheet objects modules, but not the Class object module from which they “come”.
    On the other hand: We can add a Class module , which we see then in the VBA Project window, MakeClass.JPG: https://imgur.com/GoKHDoq , but usually we cannot see the individual objects which we make from that Class.

    [Class “WorksheetType2made by us, seen as module ] _ [Class “Worksheetmade by Microsoft, invisible to us ]
    ___ [ “ShTyp2_1” ] _ [ __ ] [ _ ] ….. ___________________________ [“Sheet1”] [“Tabelle2”] [“MySheet”] [“Sht_4”]…..

    So we could make one of those Classes / class modules , for example from the VB Editor VBA Project window by selecting the appropriate right mouse click option… _..
    InsertClassModule.JPG : https://imgur.com/vcZSEAj , https://imgur.com/u1orh81
    _.. and change its name to, for example , WorksheetType2 via the VBA Project properties window
    NameClass.JPG : https://imgur.com/S6u7Gbf
    We could add some simple coding “within that object” to “make that object” , for example a simple “Name” Property.
    BuildAClass.JPG : https://imgur.com/4WGRbDC
    (There is no significance to what that Name Property for the Class WorksheetType2 is at this stage. For the Class Worksheet the Name property is given further significance due to other coding in the Worksheet Class module which we do not have any access to. )

    Class Module, Named by us -WorksheetType2
    Code:
    ' Class (Modules) : https://www.youtube.com/watch?v=jHa8W52mD1k&index=65&list=PLS7iHfqXNVhK3yzd_4XS5k4zsvnu2mkJC : https://www.youtube.com/watch?v=MjbmsVDnAL0
    Public Name As String
    We can then use that class “WorksheetType2” in a similar way to which we use the existing class “Worksheet”. We even get the options added to the intellisense drop down lists:
    SimpleWorksheetNamingCode.jpg : https://imgur.com/5pYovYt
    SimpleWorksheetNamingCode .jpg : https://imgur.com/v8ZUVVx

    So in any code module, we can now do like:
    Code:
    Sub NameAWsType2()
    ' Make a Worksheet object
    Dim Ws4 As Worksheet
     Set Ws4 = Worksheets.Item(4)
    ' Make a WorksheetType2 object
    Dim WsTyp2 As WorksheetType2
     Set WsTyp2 = New WorksheetType2
    ' Name the worksheets
     Let Ws4.Name = "Sht_4"
     Let WsTyp2.Name = "ShTyp2_1"
    ' Access the names	
     MsgBox prompt:=Ws1.Name & vbCrLf & WsTyp2.Name
    End Sub
    The way that our given name WorksheetType2 is used in coding such as that above, supports the idea that in the case of a Class the code module itself can be thought of as the Class object

    Just to help clarify. There will be somewhere “hidden” from us, a Worksheet class module, and that will include a vast amount of coding, some of which will include functions / methods which will be associated with the Worksheet Name Property. I guess if we had access to that it might be dangerous as we might change something that could cause a chaos somewhere, as other things will likely be organised in the Excel we use, based on how that coding is.
    The word New “creates” an object (a process called instantiating ).
    The internal coding which we have no access to will have created the Worksheets already “existing”.
    We have to do this instantiating for any objects we create, either
    through instancing a Class which we have made, as we are discussing here
    or
    by accessing other objects not included as default in Excel, often referred to as Binding ( http://www.excelfox.com/forum/showth...ing-Techniques )
    As I am not allowed such access to the Worksheet class, I cannot use Set __ = New ___ , I can only assign a variable to the existing object like Set __ = ___

    Finally, I try to here to sketch in
    _ the “invisible” Class object module for the standard Excel worksheets,
    and
    _ two object modules for the objects I might “make” from the see able Class object module which we “made” with the coding above
    Class Object Mess.JPG : https://imgur.com/r6hrPSK
    Attachment 2116

    [Class Worksheet]_ [First worksheet object]
    _____________________[Second worksheet object]

    _ [Class WorksheetType2 ] __ [First object (ShTyp2_1)]
    ________________________________[Second object]


    Also we have a code module, which is not so often called an object, and a Thisworkbook ( In German DieseArbeitsmappe ) code module usually regarded as an object.

    It is a mess because it is a mess. :-)

    Here is a special ”Excel” file which I have which has 6 worksheets.
    It has the Class object modules and object modules for
    the Application Excel
    and
    the worksheets. ( Each worksheet has a Class object with just one worksheet “made” from it )
    Alans Full Excel.JPG : https://app.box.com/s/iaozdmu9jhu33wo9r2ntcdhkkz1bwu9g , https://imgur.com/0k2NDVX
    Attachment 2115

    [Class ExcelAppThisWorkbook] _ [ThisWorkbook object]

    _[ Class Worksheet1 ] ________ [First worksheet object]

    _ [Class Worksheet2 ] ________ [Second worksheet object ]

    _ [Class Worksheet3 ] ________ [Third worksheet object]

    _ [Class Worksheet4 ] ________ [Forth worksheet object]

    _ [Class Worksheet5 ] ________ [Fifth worksheet object]

    _ [Class Worksheet6 ] ________ [Sixth worksheet object]

    _ [Class Worksheet7 ] ________ [Seventh worksheet object]





    Ref
    http://www.cpearson.com/excel/classes.aspx ( RiP Chip Pearson http://excelmatters.com/2018/04/30/rip-chip-pearson/ )

    Attached Images Attached Images

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

    Pubic Properly Leting Get in Class object modules

    Code for this post:
    http://www.eileenslounge.com/viewtop...=31395#p242918

    Code:
    
    
    
    
    
    
    
    
    
    
    
    
    ' Leave some lines free above
    '  http://www.eileenslounge.com/viewtopic.php?f=30&t=31395#p242918
    
    Sub WotchaGotInHorizontalClit() 'Examine what is copied to clipboard from a row, and paste it into code module
    Rem 0 Test range
    Range("A1:C1").Value = Array("A1", "B1", "C1")
    Rem 1 Clitbored
    Range("A1:C1").Copy
    Dim objDataObject As Object '  DataObject Late Binding equivalent            ' http://excelmatters.com/2013/09/23/vba-references-and-early-binding-vs-late-binding/     http://www.excelfox.com/forum/showthread.php/2240-VBA-referring-to-external-shared-Libraries-1)-Early-1-5)-Laterly-Early-and-2)-Late-Binding-Techniques
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") ' http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
     objDataObject.GetFromClipboard
    Dim strIn As String: Let strIn = objDataObject.GetText() 'String of range as held in clitbored
    Rem 2 examine string from clitbored
    Dim myLenf As Long: Let myLenf = Len(strIn)
    Dim cnt As Long
        For cnt = 1 To myLenf
        Dim Caracter As Variant ' String
         Let Caracter = Mid(strIn, cnt, 1)
        Dim WotchaGot As String
            If Caracter Like "[A-Z]" Or Caracter Like "[0-9]" Then ' Check for normal characters
             Let WotchaGot = WotchaGot & """" & Caracter & """" & " & "
            Else
             Select Case Caracter
              Case " "
               Let WotchaGot = WotchaGot & """" & " " & """" & " & "
              Case vbCr
               Let WotchaGot = WotchaGot & "vbCr & "
              Case vbLf
               Let WotchaGot = WotchaGot & "vbLf & "
              Case vbCrLf
               Let WotchaGot = WotchaGot & "vbCrLf & "
              Case """"
               Let WotchaGot = WotchaGot & """" & """" & """" & " & "
              Case vbTab
               Let WotchaGot = WotchaGot & "vbTab & "
              Case Else
               WotchaGot = WotchaGot & """" & "SomeFink" & """" & " & "
               'Let CaseElse = Caracter
             End Select
            End If
        Next cnt
        If WotchaGot <> "" Then Let WotchaGot = Left(WotchaGot, Len(WotchaGot) - 3) ' take off last " & "
     MsgBox Prompt:=WotchaGot: Debug.Print WotchaGot
    Rem 4 paste into code module
     On Error Resume Next
     ThisWorkbook.VBProject.VBComponents(Me.CodeName).CodeModule.AddFromString "Rem    " & strIn ' a Rem is added to stop the code module showing red error
     Set objDataObject = Nothing
    End Sub
    
    '
    Sub WotchaGotInCodeWindowHorizontal() ' Examine first line of text in the code module
    Rem 1 Put first line from code module into a string
    Dim strVonCodMod As String
     Let strVonCodMod = ThisWorkbook.VBProject.VBComponents(Me.CodeName).CodeModule.Lines(Startline:=1, Count:=1)
     Let strVonCodMod = Replace(strVonCodMod, "Rem    ", "", 1, -1, vbBinaryCompare)
    Rem 2 examine string from code module line 1
    Dim myLenf As Long: Let myLenf = Len(strVonCodMod)
    Dim cnt As Long
        For cnt = 1 To myLenf
        Dim Caracter As Variant ' String
         Let Caracter = Mid(strVonCodMod, cnt, 1)
        Dim WotchaGot As String
            If Caracter Like "[A-Z]" Or Caracter Like "[0-9]" Then
             Let WotchaGot = WotchaGot & """" & Caracter & """" & " & "
            Else
             Select Case Caracter
              Case " "
               Let WotchaGot = WotchaGot & """" & " " & """" & " & "
              Case vbCr
               Let WotchaGot = WotchaGot & "vbCr & "
              Case vbLf
               Let WotchaGot = WotchaGot & "vbLf & "
              Case vbCrLf
               Let WotchaGot = WotchaGot & "vbCrLf & "
              Case """"
               Let WotchaGot = WotchaGot & """" & """" & """" & " & "
              Case vbTab
               Let WotchaGot = WotchaGot & "vbTab & "
              Case Else
               WotchaGot = WotchaGot & """" & "SomeFink" & """" & " & "
               'Let CaseElse = Caracter
             End Select
            End If
        Next cnt
        If WotchaGot <> "" Then Let WotchaGot = Left(WotchaGot, Len(WotchaGot) - 3)
     MsgBox Prompt:=WotchaGot: Debug.Print WotchaGot
    Rem 3 clipbored
    '3a Put string from first code module line in clipbored
    Dim objDataObject As Object '
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
     objDataObject.SetText strVonCodMod
     objDataObject.PutInClipboard
     Set objDataObject = Nothing
    '3b paste string from first code module line into worksheet
     Range("A1:C1").ClearContents
     Paste Destination:=Range("A1")
    Rem 4 Delete first line from code module
     On Error Resume Next
     ThisWorkbook.VBProject.VBComponents(Me.CodeName).CodeModule.DeleteLines Startline:=1, Count:=1
    End Sub
    
    
    '
    Sub WotchaGotInVirticalClit() ''Examine what is copied to clipboard from a column, and paste it into code module
    Rem 0 Test range
    Dim WhoRay(1 To 3, 1 To 1) As String: Let WhoRay(1, 1) = "A1": Let WhoRay(2, 1) = "A2": Let WhoRay(3, 1) = "A3"
     Let Range("A1:A3").Value = WhoRay
    Rem 1 Clipboard
     Range("A1:A3").Copy
    Dim objDataObject As Object
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
     objDataObject.GetFromClipboard
    Dim strIn As String: Let strIn = objDataObject.GetText()
    Rem 2 Examine string held in clipboard from a copy from a column
    Dim myLenf As Long: Let myLenf = Len(strIn)
    Dim cnt As Long
        For cnt = 1 To myLenf
        Dim Caracter As Variant ' String
         Let Caracter = Mid(strIn, cnt, 1)
        Dim WotchaGot As String
            If Caracter Like "[A-Z]" Or Caracter Like "[0-9]" Then
             Let WotchaGot = WotchaGot & """" & Caracter & """" & " & "
            Else
             Select Case Caracter
              Case " "
               Let WotchaGot = WotchaGot & """" & " " & """" & " & "
              Case vbCr
               Let WotchaGot = WotchaGot & "vbCr & "
              Case vbLf
               Let WotchaGot = WotchaGot & "vbLf & "
              Case vbCrLf
               Let WotchaGot = WotchaGot & "vbCrLf & "
              Case """"
               Let WotchaGot = WotchaGot & """" & """" & """" & " & "
              Case vbTab
               Let WotchaGot = WotchaGot & "vbTab & "
              Case Else
               WotchaGot = WotchaGot & """" & "SomeFink" & """" & " & "
               Let CaseElse = Caracter
             End Select
            End If
        Next cnt
        If WotchaGot <> "" Then Let WotchaGot = Left(WotchaGot, Len(WotchaGot) - 3)
     MsgBox Prompt:=WotchaGot: Debug.Print WotchaGot
    Rem 4 Paste stringt from clipboard into top of code module
     On Error Resume Next
     ThisWorkbook.VBProject.VBComponents(Me.CodeName).CodeModule.AddFromString "Rem    " & Replace(strIn, vbLf, vbLf & "Rem    ", 1, 2, vbBinaryCompare)
     Set objDataObject = Nothing
    End Sub
    
    Sub WotchaGotInCodeWindowVertical() ' Examins what is held in a code module after pasting in a column froma worksheet
    Rem 1 Put first 4 lines from code module into a string
    Dim strVonCodMod As String
     Let strVonCodMod = ThisWorkbook.VBProject.VBComponents(Me.CodeName).CodeModule.Lines(Startline:=1, Count:=4)
     Let strVonCodMod = Replace(strVonCodMod, "Rem    ", "", 1, -1, vbBinaryCompare)
    Rem 2 Examine contents of string
    Dim myLenf As Long: Let myLenf = Len(strVonCodMod)
    Dim cnt As Long
        For cnt = 1 To myLenf
        Dim Caracter As Variant ' String
         Let Caracter = Mid(strVonCodMod, cnt, 1)
        Dim WotchaGot As String
            If Caracter Like "[A-Z]" Or Caracter Like "[0-9]" Then
             Let WotchaGot = WotchaGot & """" & Caracter & """" & " & "
            Else
             Select Case Caracter
              Case " "
               Let WotchaGot = WotchaGot & """" & " " & """" & " & "
              Case vbCr
               Let WotchaGot = WotchaGot & "vbCr & "
              Case vbLf
               Let WotchaGot = WotchaGot & "vbLf & "
              Case vbCrLf
               Let WotchaGot = WotchaGot & "vbCrLf & "
              Case """"
               Let WotchaGot = WotchaGot & """" & """" & """" & " & "
              Case vbTab
               Let WotchaGot = WotchaGot & "vbTab & "
              Case Else
               WotchaGot = WotchaGot & """" & "SomeFink" & """" & " & "
               'Let CaseElse = Caracter
             End Select
            End If
        Next cnt
        If WotchaGot <> "" Then Let WotchaGot = Left(WotchaGot, Len(WotchaGot) - 3)
     MsgBox Prompt:=WotchaGot: Debug.Print WotchaGot
    Rem 3 Clipboard
    '3a Put string into clipboard
    Dim objDataObject As Object '
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
     objDataObject.SetText strVonCodMod
     objDataObject.PutInClipboard
     Set objDataObject = Nothing
    '3b Paste into worksheet from clipboard
     Paste Destination:=Range("A1")
    Rem 4 Delet first 4 rows from code module
     On Error Resume Next
     ThisWorkbook.VBProject.VBComponents(Me.CodeName).CodeModule.DeleteLines Startline:=1, Count:=4
    End Sub

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

    Continuation fron last Post and Extra codes for Yasser:

    Continued from above....
    Code:
    Sub Pubic_Properly_Let_RngAsString_() ' Examination of a range  copied to clipboard, then paste to Private Class code module
     Range("A1:C1").Value = Array("A1", "B1", "C1")
     Range("A2:C2").Value = Array("A2", "B2", "C2")
     Range("A3:C3").Value = Array("A3", "B3", "C3")
     Range("A1:C3").Copy
    Dim objDataObject As Object
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
     objDataObject.GetFromClipboard
    Dim strIn As String: Let strIn = objDataObject.GetText()
    Dim myLenf As Long: Let myLenf = Len(strIn)
    Dim cnt As Long
        For cnt = 1 To myLenf
        Dim Caracter As Variant ' String
         Let Caracter = Mid(strIn, cnt, 1)
        Dim WotchaGot As String
            If Caracter Like "[A-Z]" Or Caracter Like "[0-9]" Then
             Let WotchaGot = WotchaGot & """" & Caracter & """" & " & "
            Else
             Select Case Caracter
              Case " "
               Let WotchaGot = WotchaGot & """" & " " & """" & " & "
              Case vbCr
               Let WotchaGot = WotchaGot & "vbCr & "
              Case vbLf
               Let WotchaGot = WotchaGot & "vbLf & "
              Case vbCrLf
               Let WotchaGot = WotchaGot & "vbCrLf & "
              Case """"
               Let WotchaGot = WotchaGot & """" & """" & """" & " & "
              Case vbTab
               Let WotchaGot = WotchaGot & "vbTab & "
              Case Else
               WotchaGot = WotchaGot & """" & "SomeFink" & """" & " & "
             End Select
            End If
        Next cnt
        If WotchaGot <> "" Then Let WotchaGot = Left(WotchaGot, Len(WotchaGot) - 3)
     MsgBox Prompt:=WotchaGot: Debug.Print WotchaGot: Debug.Print
     MsgBox Prompt:=Replace(WotchaGot, "vbLf & ", "vbLf" & vbCrLf, 1, -1, vbBinaryCompare): Debug.Print Replace(WotchaGot, "vbLf & ", "vbLf" & vbCrLf, 1, -1, vbBinaryCompare): Debug.Print
     MsgBox Prompt:=Replace(WotchaGot, "vbTab", """ | """, 1, -1, vbBinaryCompare): Debug.Print Replace(WotchaGot, "vbTab", """ | """, 1, -1, vbBinaryCompare): Debug.Print
     
     Let strIn = Replace(strIn, vbTab, " | ", 1, -1, vbBinaryCompare) ' replace tab with  |
     MsgBox Prompt:=strIn: Debug.Print strIn
     
     Let strIn = "Rem    " & Replace(strIn, vbLf, vbLf & "Rem    ", 1, 2, vbBinaryCompare) ' add some Rems to prevent red error in code window
     Debug.Print
     On Error Resume Next
     ThisWorkbook.VBProject.VBComponents("Tabelle1").CodeModule.AddFromString strIn
     Set objDataObject = Nothing
    End Sub
    
    Sub Fumic_Properly_Get_Rng_AsString() ' Paste rworksheet range stored in code modulle back to worksheet
    Range("A1:C3").ClearContents
    '
     Dim strVonCodMod As String
     Let strVonCodMod = ThisWorkbook.VBProject.VBComponents("Tabelle1").CodeModule.Lines(Startline:=1, Count:=4)
     Let strVonCodMod = Replace(strVonCodMod, "Rem    ", "", 1, -1, vbBinaryCompare)
     Let strVonCodMod = Replace(strVonCodMod, " | ", vbTab, 1, -1, vbBinaryCompare)
    Dim objDataObject As Object '
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
     objDataObject.SetText strVonCodMod
     objDataObject.PutInClipboard
     Set objDataObject = Nothing
     Paste Destination:=Range("A1")
     On Error Resume Next
     ThisWorkbook.VBProject.VBComponents("Tabelle1").CodeModule.DeleteLines Startline:=1, Count:=4
    End Sub
    _.________________________________________________ ______________
    Extra Codes For Yassers Normal Excel File, "NormalExcelFile.xlsm" : http://eileenslounge.com/viewtopic.p...=31395#p242964
    Code:
    Option Explicit
    Private Sub Publics_Probably_Let_RngAsString__() ' Input of range to Private Properties storage
    Rem 0 test data range is selection. Select a range before running this code
    Dim rngSel As Range: Set rngSel = Selection ' selected range for later reference
    Rem 1 Copy range to clipbored
     rngSel.Copy
    Rem 2 put data currently in clipboard into a string
    Dim objDataObject As Object ' DataObject  ' This will be for an an Object from the class MS Forms. This will be a Data Object of what we "send" to the Clipboard. But it is a DataObject. It has the Methods I need to send to and get text to the Clipboard. ' http://excelmatters.com/2013/09/23/vba-references-and-early-binding-vs-late-binding/     http://www.excelfox.com/forum/showthread.php/2240-VBA-referring-to-external-shared-Libraries-1)-Early-1-5)-Laterly-Early-and-2)-Late-Binding-Techniques
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") ' http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
     objDataObject.GetFromClipboard ' The data object has the long text string from the clipboard at this point
     'rngSel.ClearContents ' we can't do this here, not sure why??
    Dim strIn As String: Let strIn = objDataObject.GetText() ' The string variable, strIn, is given the long string
     rngSel.ClearContents ' do this now. (If we did it before, the contents of the clipboard are typically emptied, so that would be poo. I don't know why the clipboard needs to be full still fir the last code line??
    Rem 3 manipulate string to substitute vbTab with arbritrary character combination - in next code this will be replaced. We do this because the vbTab is lost when pasting into a code module
     Let strIn = Replace(strIn, vbTab, " | ", 1, -1, vbBinaryCompare) ' replacing( in the string , replace vbTab  , with " | " , start at first position ,  replace all occurances , look for an excact case sensitive match as this is qiucker if we don't need to be case insensitive as with option vbTextCompare )
     Let strIn = "'_-" & Replace(strIn, vbLf, vbLf & "'_-", 1, -1, vbBinaryCompare) ' add some comment bits to prevent red error in code window
    Rem 4 add range data
     Let strIn = "'_-Worksheets(""" & rngSel.Parent.Name & """).Range(""" & rngSel.Address & """)" & vbCrLf & strIn ' Add an extra first header line to indicate the worksheet and range used
     On Error Resume Next ' I am not quite sure why this is needed
     ThisWorkbook.VBProject.VBComponents("YassersDump").CodeModule.AddFromString strIn ' As far as i know, this adds from the start of the module.
     Set objDataObject = Nothing ' This probably is not needed.                                                      It upsets Kyle when i do it, but he can take it :-)
    End Sub
    
    Private Sub Publics_Probably_Get_Rng__AsString() ' Output of range from Private Properties Storage
    Rem 2 get string data form code module Private properties storage
    Dim strVonCodMod As String
    '2a Range infomation first line
    Dim Ws As Worksheet, Rng As Range ' These will be used for the range identification infomation which the next code line gets from the first line in the code module used for the
     Let strVonCodMod = ThisWorkbook.VBProject.VBComponents("YassersDump").CodeModule.Lines(Startline:=1, Count:=1) ' First line has the
     Let strVonCodMod = Replace(Replace(Replace(strVonCodMod, "'_-Worksheets(""", ""), """).Range(""", " "), """)", "") ' we want to reduce and change like  "Worksheets("Sht").Range("A1")"  to   "Sht A1"    so that we can use split to get the Sheet name and the range address   strVonCodMod = Replace(strVonCodMod, "'_-Worksheets(""", "") :  strVonCodMod = Replace(strVonCodMod, """).Range(""", " ") :  strVonCodMod = Replace(strVonCodMod, """)", "")
     Set Ws = Worksheets(Split(strVonCodMod)(0)): Set Rng = Ws.Range(Split(strVonCodMod)(1)) ' The returned array from spliting by the space , " " ,  will have first element (indicie(0)) of like  "Sht"  and the second element (indicie(1))  of like  "A1"
    '2b get range data
     Let strVonCodMod = ThisWorkbook.VBProject.VBComponents("YassersDump").CodeModule.Lines(Startline:=2, Count:=Rng.Rows.Count + 1) ' We need rows count+1 because there seems to be a last  & vbCr & vbLf    http://eileenslounge.com/viewtopic.php?f=30&t=31395#p242941
     Let strVonCodMod = Replace(strVonCodMod, "'_-", "", 1, -1, vbBinaryCompare) ' remove the '_- Comment bits
     Let strVonCodMod = Replace(strVonCodMod, " | ", vbTab, 1, -1, vbBinaryCompare) ' Replace the " | " with a carriage return
    Rem 3 Put the string into the clipboard
    Dim objDataObject As Object '
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
     objDataObject.SetText strVonCodMod
     objDataObject.PutInClipboard
     Set objDataObject = Nothing
    Rem 4 Output range data values to spreadsheet
     Ws.Paste Destination:=Rng
    Rem 5
     On Error Resume Next
     ThisWorkbook.VBProject.VBComponents("YassersDump").CodeModule.DeleteLines Startline:=1, Count:=Rng.Rows.Count + 1 + 1 ' remove the first header row and all data and the extra last row caused by the extra  & vbCr & vbLf
    End Sub

    ( XL2020alsm.xlsb https://app.box.com/s/26frr0zzc93q6zsraktove3qypqj714p )
    Attached Files Attached Files

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

    Sub PubProliferous_Let_RngAsString__()

    Routine for following excelfox Thread:
    http://www.excelfox.com/forum/showth...0863#post10863 ...


    Code:
    Sub PubProliferous_Let_RngAsString__() ' Make hardcopy of spreadsheet range to VB Editor insensibly  http://www.eileenslounge.com/viewtopic.php?f=30&t=31395#p243002
    Rem 0 VBA project instantiated VBIDE
    Dim VBIDEVBAProj As Object ' For convenience a variable is used for this code module
     Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.codemodule                                                 ' ThisWorkbook.VBProject.VBComponents(Me.CodeName) 'varible referring to this code module
    Rem 1 Indicate that this module is being used for text.
        If Not Right(VBIDEVBAProj.Name, 4) = "_txt" Then Let VBIDEVBAProj.Name = VBIDEVBAProj.Name & "_txt" ' If Not Right(Me.CodeName, 4) = "_txt" Then Let VBIDEVBAProj.Name = Me.CodeName & "_txt"
    Rem 2 Selected range to clipboard
    Dim rngSel As Range: Set rngSel = Selection: rngSel.Copy
    Dim objDataObject As Object ' DataObject  ' This will be for an an Object from the class MS Forms. This will be a Data Object of what we "send" to the Clipboard. But it is a DataObject. It has the Methods I need to send to and get text to the Clipboard. ' http://excelmatters.com/2013/09/23/vba-references-and-early-binding-vs-late-binding/     http://www.excelfox.com/forum/showthread.php/2240-VBA-referring-to-external-shared-Libraries-1)-Early-1-5)-Laterly-Early-and-2)-Late-Binding-Techniques
     Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") ' http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
     objDataObject.GetFromClipboard ' The data object has the long text string from the clipboard at this point
    Dim strIn As String: strIn = objDataObject.GetText() 'This gets the test string from the Data Object
    ' rngSel.ClearContents ' range is cleared after copying table values to clipboard
    Rem 3
    '3a) replace vbTab with  "|"  as cell divider to use in the VB editor range value display
     Let strIn = Replace(strIn, vbTab, "|") '                                                             : Call WotchaGot(strIn)
    '3b) typically the last two "characters" from the text obtained from a spreadsheet range via the clipboard has a last vbCr & vbLf pair. We rely on this in further lines so this is just to be sure
       If Not Right(strIn, 2) = vbCr & vbLf Then Let strIn = strIn & vbCr & vbLf ' Typically a last vbcr & vblf is there, and we rely on it, so we make sure here ###
    Rem 4 add start and stop info
     Let strIn = "'_-" & Format(Date, "DD MM YYYY") & " Worksheets(""" & rngSel.Parent.Name & """).Range(""" & rngSel.Address & """)" & vbCr & vbLf & strIn & "'_- EOF " & Format(Date, "DD MM YYYY") ' Note in last bit I am relying on having a vbcr & vbLf after existing strIn ###
    Rem 5 Make array from string using the  vbCr & vbLf  pair as seperator.  This willbe an array of  data and the extra start and end rows
    Dim SpltRws() As String: Let SpltRws() = Split(strIn, vbCr & vbLf, -1, vbBinaryCompare)
    Rem 6 Determination of code module table characteristics
    '6a) from split rows array, we can get the number of columns and rows
    Dim RwCnt As Long, ClCnt As Long
     Let RwCnt = (UBound(SpltRws()) - LBound(SpltRws())) + 1 ' Allow for any base
    Dim SpltCls() As String: Let SpltCls() = Split(SpltRws(LBound(SpltRws()) + 1), "|", -1, vbBinaryCompare) ' assume second row is representative of all rows for column number
     Let ClCnt = (UBound(SpltCls()) - LBound(SpltCls())) + 1
    '6b) The next line is a way to make a free line...   Because we give a line number in the argument .insertlines Line:= of greater than the current last line number, then that actual number given bears no relation to the actual line number of the code line at which it will be added. ( The line number of the code I am talking about here is , as defined by, or rather as held internally by, and accessed in code coding, by a sequential integer starting at 1 at the top of the code window and counting by +1 for every successive line/row )  Because we give a line number in the argument .insertlines Line:= of greater than the current last line number, then lines will always be added at the next free line, that is to say one line above the last used line. The actual number we give is irrelevant, for numbers we give which are greater than that of the current last used line in the code module.
     VBIDEVBAProj.insertlines Line:=VBIDEVBAProj.countoflines + 9996, String:="" ' An attempt to insert a line anywhere above the last used line will force a new line at the end. So this is how we force a space. (Trying to insert a line anywhere above the last used line won't work.
    '6c) Find next free row and last row that we will effectively use
    Dim CdTblStt As Long, CdTblStp As Long ' these variables will actual hold our start and end lines, but when used below they actually force a new line by virtual of attempting to insert a line above the current last line
     Let CdTblStt = VBIDEVBAProj.countoflines + 1 ' We find that + 1 or more will take us to the next free line. (We can insert below or equal to last used line and then all will be shifted up. If we add to the last line  =___.CountOfLines  then the last line will shift up. Effectively CdTblStt is the start row as it is one up from the last row. But if we used any number >=1 for the 1 , then the actual start line which we obtain would still be at  .countoflines + 1
     Let CdTblStp = CdTblStt + RwCnt - 1 ' last row in this code module to be used. In actual fact this nimber is what it will be. Effectively with using this later in our code, we try to insert at one line furthter than the last line. For any attempt at an insert >= .countoflines+1 we actually add a new line at the end.
    Rem 7 Add lines from array to to code module , using some string formating                                       http://www.excelfox.com/forum/showthread.php/2230-Built-in-VBA-methods-and-functions-to-alter-the-contents-of-existing-character-strings  ---   Dim TabulatorSyncrenator As String: Let TabulatorSyncrenator = "123456789" ' any lengthed string
    '7a) Header
     VBIDEVBAProj.insertlines Line:=CdTblStt, String:=SpltRws(LBound(SpltRws()))
    '7b) Main looping Start for data rows ===============================
    Dim Rws As Long
        For Rws = CdTblStt + 1 To CdTblStp - 1 Step 1 ' At each row of data
        Dim rvec As Long:  Let rvec = -CdTblStt + LBound(SpltRws()) ' This gives the adjustment necerssary to take us from a code module line number to an array indicie in the range rows array, SpltRws(). This works as follows: Our used row number actually forces a new line which has that line number. For the relavant array line number, for example , the first line will need to be the first indicie. For zero base, we need to take off excactly  CdTblStt  For base 1 iwe need to take off 1 less,  so rvec  would be  -(CdTblStt + 1)
         Let SpltCls() = Split(SpltRws(Rws + rvec), "|", -1, vbBinaryCompare) 'Split each data row into data columns
        '7c) to allow some formatting, a string is built up from each column/cell value
        Dim Cls As Long
            For Cls = LBound(SpltCls()) To UBound(SpltCls())
            Dim TabulatorSyncrenator As String: Let TabulatorSyncrenator = "123456789" ' any lengthed string will do
             LSet TabulatorSyncrenator = Trim(SpltCls(Cls)) '   this cause a number like " 56" to change to "56       "  This allows us to have a fixed length format here in the displayed code editor
            Dim LineAut As String
             Let LineAut = LineAut & " | " & TabulatorSyncrenator ' : Debug.Print LineAut
            Next Cls
         Let LineAut = Replace(LineAut, " | ", "'_-", 1, 1, vbBinaryCompare) 'Replace first " | " with some sort of 'comment thing
         VBIDEVBAProj.insertlines Line:=Rws, String:=LineAut ' Note: you could use any from and including one more than the last current line. - effectively here we always try to go >=+1, we are not really defining the line, but just making sure that we add on to the end. Effectively the number in the Line:= does become the line where the string is finally. But it is not directly defined by that.
         Let LineAut = "" ' Ready for next line use
        Next Rws ' End main data rows Loop ==============================
    '7d) End row
     VBIDEVBAProj.insertlines Line:=CdTblStp, String:=SpltRws(UBound(SpltRws())) ' Note: this line would not go further than last line, so it must be done here ***
    End Sub

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

    Sub PubProliferous_Get_Rng__AsString()

    Routine for following excelfox Thread
    http://www.excelfox.com/forum/showth...0864#post10864 .....





    Code:
    Sub PubProliferous_Get_Rng__AsString() ' This pastes out all held table range values in this code module
    Rem 0 VBA project instantiated VBIDE
    Dim VBIDEVBAProj As Object ' For convenience a variable is used for this code module
     Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.codemodule                                                 ' ThisWorkbook.VBProject.VBComponents(Me.CodeName) 'varible referring to this code module
    Rem 1 Do it all
        Do: Dim EndOFSub As Boolean ' looping while not at End Sub =================================
            Do: Dim FOB As Boolean ' looping while in range data ------------------------------
            Dim ReedLineIn As String
                If ReedLineIn = "" Then ' because there is no code line in the next line we will go to  Let ReedLineIn =     if the condition "" is met
                'for an empty line we do nothing apart from having already deleted it ( for all but the first time here at the code start)
                Else ' We are in data or start or stop-----------------|
                Dim arrOut As String ' A string for output from clipboard for each found range
                    If Mid(ReedLineIn, 15, 12) = "Worksheets(""" Then ' we are at backward looping end(start) of data
                     Let ReedLineIn = Replace(Replace(Mid(ReedLineIn, 27), """).Range(""", " "), """)", "") 'Let ReedLineIn = Mid(ReedLineIn, 27): ReedLineIn = Replace(ReedLineIn, """).Range(""", " ", 1, 1, vbBinaryCompare): ReedLineIn = Replace(ReedLineIn, """)", "", 1, 1, vbBinaryCompare)
                     'MsgBox ReedLineIn: Debug.Print ReedLineIn ' ' This is particularly useful in developing codes of this nature, as usally step  (F8)  mode will often fail due to code lines referrencig this code module  which trip up the process somehow
                    Dim Ws As Worksheet, Rng As Range 'variables to use for output range details
                     Set Ws = Worksheets(Split(ReedLineIn)(0)): Set Rng = Ws.Range(Split(ReedLineIn)(1)) ' The returned array from spliting by the space , " " ,  will have first element (indicie(0)) of like  "Sheet1"  and the second element (indicie(1))  of like  "$B$1:$D$13"
                    ' Section to prepare data for, and to do, the paste out of a data value range                                                                                                     Output preparing section !!
                     'MsgBox arrOut: Debug.Print arrOut
                     Let arrOut = Replace(Replace(arrOut, "'_-", ""), " | ", vbTab) ' The "inner" Replace takes out the "'_-" bit at the start of a line, and the "outer" Replace changes the seperator used in the code module  " | "    for that which appears to be used by Excel to determine a cell "wall"  vbTab
                     'MsgBox arrOut: Debug.Print arrOut
                     Let arrOut = Replace(arrOut, "  ", "", 1, -1, vbBinaryCompare) ' this is intended as a partial solution to removing most of the extra spaces that we added, whilst not removing any intentionally there. You may want to adjust this along with the actual character used to fill in the unused spaces in oder to come up with a better solution to suit specific data types
                     'MsgBox arrOut: Debug.Print arrOut     'WotchaGot (arrOut) ' routine to examine contents of string
                    Dim objDataObject As Object: Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"): objDataObject.SetText arrOut: objDataObject.PutInClipboard ' Text is given to Data object which in turn uses its method to put that in the clipboard
                     Ws.Paste Destination:=Rng 'Worksheets Paste method with optional argument to determine where, ( default would be from top left of active range )
                     Let arrOut = "" ' Clear the string to allow for collection of next range
                        If Right(VBIDEVBAProj.Name, 4) = "_txt" Then Let VBIDEVBAProj.Name = Replace(VBIDEVBAProj.Name, "_txt", "", 1, 1, vbBinaryCompare)
                    Else
                    ' Section to collect the range value data ( If not at the end section of a data range held in the code window like  '_- EOF 22 12 2018 )
                        If Left(ReedLineIn, 8) = "'_- EOF " Then '
                        ' Let FOB = True ' Let FOB = True is not needed, as clearing the string arrOut effectively starts us again afresh
                        'for last data we do nothing apart from having already deleted it
                        Else ' from here we are in data collecting/concatanating into string arrOut +++++
                         Let arrOut = ReedLineIn & vbCr & vbLf & arrOut   ' A simple concatenation along with a new line indicator will give a convenient format of the final data range for use in the Output preparing section !! above  Note: we build the string "bachwards" with the next line as first and previous lies after it because the code is looping backwards
                        End If ' we were collecting/concatenating range value data                  +++++
                    End If
                End If ' we are did stuff in data or start or stop-----|
            Let ReedLineIn = VBIDEVBAProj.Lines(StartLine:=VBIDEVBAProj.countoflines, Count:=1)
                If ReedLineIn = "End Sub" Or ReedLineIn = "End Function" Then
                 Let EndOFSub = True
                Else ' after reading in any line, we delete it, unless it was the End of a routine
                 VBIDEVBAProj.DeleteLines StartLine:=VBIDEVBAProj.countoflines, Count:=1
                End If
            Loop While Not EndOFSub = True ' And FOB = False '------------------------------------
         'MsgBox Prompt:="In between data ranges": Let FOB = False ' we could do something here to tell us we are in between range, such as count the ranges, and then set FOB back to zero
        Loop While EndOFSub = False ' ================================================================
    End Sub

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

    Sub PubeProFannyTeas__GLetner(ByVal strDte As String)

    Routine for following excelfox Thread
    http://www.excelfox.com/forum/showth...0865#post10865


    Code:
    Sub TestieCall()
     Call PubeProFannyTeas__GLetner("23 12 2018")
    End Sub
    Sub PubeProFannyTeas__GLetner(ByVal strDte As String)
    Rem 0 VBA project instantiated VBIDE
    Dim VBIDEVBAProj As Object ' For convenience a variable is used for this code module
     Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.codemodule                                                 ' ThisWorkbook.VBProject.VBComponents(Me.CodeName) 'varible referring to this code module
    Rem 1 This code module data range
    '1a) get full data range as string
    Dim Cnt As Long, Lr As Long, ReedLineIn As String
     Let Lr = VBIDEVBAProj.countoflines: Let Cnt = Lr + 1
        Do
         Let Cnt = Cnt - 1
         Let ReedLineIn = VBIDEVBAProj.Lines(StartLine:=Cnt, Count:=1)
        Loop While Not (Left(ReedLineIn, 7) = "End Sub" Or Left(ReedLineIn, 7) = "End Fun")
        If Cnt = Lr Then MsgBox Prompt:="No range data values in code module  " & VBIDEVBAProj.Name: Exit Sub
    '1b) Complete data region as single string.
    Dim strIn As String: Let strIn = VBIDEVBAProj.Lines(StartLine:=Cnt + 1, Count:=Lr - Cnt)
     Let strIn = Mid(strIn, 3) ' take off first vbCr & vbLf
     'WotchaGot (strIn)
    '1c) split into date ranges, get most recent of any dates to match given  strDte
    Dim DtedRngs() As String: Let DtedRngs() = Split(strIn, vbCr & vbLf & vbCr & vbLf) ' Split range by empty line which is double  vbCr & vbLf
     'WotchaGot (DtedRngs(0)): Debug.Print: WotchaGot (DtedRngs(1))
        For Cnt = UBound(DtedRngs()) To LBound(DtedRngs()) Step -1
        '1d)Check for date match, if so the main code working begins
            Dim FndDte As String: Let FndDte = Mid(DtedRngs(Cnt), 4, 10) ' looking at like this typical start of a data range,    '_-23 12 2018 Wo....  we see that 10 characters from character 4 will give us the date
            If FndDte = strDte Then
             'MsgBox Prompt:=FndDte
            Rem 2 manipulation of found date range
            Dim strRng As String: Let strRng = DtedRngs(Cnt)
             Let strRng = Mid(strRng, 27) 'takes off up to start of worksheet name... no speacial reason toher than why not? - its not needed anymore
            '2a) range info
            Dim RngInfo As String: Let RngInfo = Left(strRng, InStr(1, strRng, """)" & vbCr & vbLf, vbBinaryCompare) - 1) '    This gets us at like        Tabelle1").Range("$I$2513:$J$2514
            Dim ShtName As String, RngAdrs As String
             Let ShtName = Split(RngInfo, """).Range(""", 2, vbBinaryCompare)(0) '    split above string ,  using as seperator  ").Range("   ,  into 2 bits   ,   for exact computer binary type compare     Then we have first array element (indicie (0)) as the worksheet name  and the second array element (indicie (1)) as the range address
             Let RngAdrs = Split(RngInfo, """).Range(""", 2, vbBinaryCompare)(1) ': Debug.Print ShtName & "  " & RngAdrs
            Dim Ws As Worksheet, Rng As Range: Set Ws = Worksheets("" & ShtName & ""): Set Rng = Ws.Range(RngAdrs)
            '2b) get data value range
             Let strRng = Mid(strRng, InStr(1, strRng, vbCr & vbLf, vbBinaryCompare) + 2) ' take off first line & the first vbCr & vbLf
             Let strRng = Left(strRng, InStr(1, strRng, "'_- EOF ", vbBinaryCompare) - 1) ' take off last line, ( but leave on the vbCr & vbLf as that seems to typically be on a string from an excel range
             'WotchaGot strRng
             Let strRng = Replace(strRng, " | ", vbTab, 1, -1, vbBinaryCompare) 'Change code window cell wall seperator for that used by Excel
             Let strRng = Replace(strRng, "'_-", "", 1, -1, vbBinaryCompare)
             Let strRng = Replace(strRng, "  ", "", 1, -1, vbBinaryCompare) ' Bit of bodge to remove my added spaces
             'Debug.Print strRng
            Rem 3 output to worksheet
            Dim objDataObject As Object: Set objDataObject = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"): objDataObject.SetText strRng: objDataObject.PutInClipboard ' Text is given to Data object which in turn uses its method to put that in the clipboard
             Ws.Paste Destination:=Rng 'Worksheets Paste method with optional argument to determine where, ( default would be from top left of active range )
             Exit Sub 'This code only gets the first found range looking from code window bottom
            Else '     No matching date found yet, so do nothing but
            End If '    go on to
        Next Cnt '    next date range ' ( There is no check for no matching date. The code will simple end after all ranges have been looped through.)
    End Sub

  10. #170
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,522
    Rep Power
    10
    Code for Yassser here:
    http://www.eileenslounge.com/viewtop...=31529#p243999

    Code:
    Option Explicit
    'I have numbers from 1 to 2319 made in groups in different numbers (in ten groups) as shown in column F
    'How can I get random distribution for those group to have the same range of numbers from 1 to 2319
    'but in different order and at the same time to have the same number inside each group
    'Example
    'Group 6 from 1267 - 1489 >> the number inside that group is 223
    'Suppose the random choice make this group the first one so the expected result would be 1 - 223
    '
    'then suppose the second selected group is group 8 which is 1699 - 1938 >> the number inside that group is 240
    'So that new group in the expected result would start at 224
    '(which is the last number in the previous result and the finish number would be 463
    '
    '...
    'Is it possible to do that in random order?
    '
    Sub RandomDistribution4Numbers() ' http://www.eileenslounge.com/viewtopic.php?f=30&t=31529
    Dim Ws1 As Worksheet: Set Ws1 = Worksheets("Sheet1")
    Dim arrSN() As Variant: Let arrSN() = Ws1.Range("F2:F" & Ws1.Range("F" & Rows.Count & "").End(xlUp).Row & "").Value ' range of current SNs
    Dim LstGrpStp As Long: Let LstGrpStp = 0 ' last number used at end of random number group
    Dim arrGrpsOut() As String: ReDim arrGrpsOut(1 To UBound(arrSN(), 1), 1 To 1) ' Array for output values
        Do ' we loop while we have not yet filled all of the output array, arrGrpsOut()
        Dim Rnd1ToUBnd As Long ' For a random array indicie from 1 to the UBound "row" of the input, (and output), arraysd
        Randomize: Let Rnd1ToUBnd = Int(UBound(arrSN(), 1) * Rnd) + 1
            If arrGrpsOut(Rnd1ToUBnd, 1) = "" Then ' Not yet filled this element in output array, so do the main stuff
            Dim OutElsFilled As Long: Let OutElsFilled = OutElsFilled + 1 ' count of number of outup array elements filled
            ' split F column (arrSN())  numbers to get range of numbers
            Dim SpltRng() As String: Let SpltRng() = Split(arrSN(Rnd1ToUBnd, 1), " - ", 2, vbBinaryCompare)
            Dim Rng As Long: Let Rng = SpltRng(1) - SpltRng(0) ' Range of numbers
            Dim Stt As Long, Stp As Long: Let Stt = LstGrpStp + 1: Let Stp = LstGrpStp + Rng + 1 ' Start and stop of range of numbers
            ' build output array with the numbers
             Let arrGrpsOut(Rnd1ToUBnd, 1) = Stt & " - " & Stp
             Let LstGrpStp = Stp ' Last highest used number
            Else ' If we come here then our random number must of been for an indicie of an array element already filled - so this probably makes the code a bit inefficient
            End If
        Loop While OutElsFilled < UBound(arrSN(), 1) ' we loop while we have not yet filled all of the output array, arrGrpsOut(), which is determined by if we did the main stuff as many times as there are elements in the input/Output arrays
    
     Let Ws1.Range("G2").Resize(UBound(arrSN(), 1)).Value = arrGrpsOut
    End Sub
    '
    
    
    
    
    
    Sub RandomizeGroups() ' Hans code ' http://www.eileenslounge.com/viewtopic.php?f=30&t=31529#p244006
        Dim arr   As Variant
        Dim lb    As Long
        Dim ub    As Long
        Dim i     As Long
        Dim j     As Long
        Dim tmp   As Long
        Dim n     As Long
        Dim idx() As Long
        Dim itm() As String
        Dim grp() As String
        arr = Range("F2:F11").Value
        lb = LBound(arr, 1)
        ub = UBound(arr, 1)
        ReDim idx(lb To ub)
        ReDim grp(lb To ub)
        For i = lb To ub
            idx(i) = i
        Next i
        For i = lb To ub
            j = Application.RandBetween(lb, ub)
            tmp = idx(i)
            idx(i) = idx(j)
            idx(j) = tmp
        Next i
        n = 1
        For i = lb To ub
            itm = Split(arr(idx(i), 1), " - ")
            grp(idx(i)) = n & " - " & n + itm(1) - itm(0)
            n = n + itm(1) - itm(0) + 1
        Next i
        Range("G2:G11").Value = Application.Transpose(grp)
    End Sub

    Typical results from my code are shown in column G. ( The code works on the data from column F )

    _____ Workbook: Sample.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    E
    F
    G
    H
    I
    1
    for illustration
    SN
    Some expected result Number inside Group
    2
    1
    1 - 244
    923 - 1166
    244
    3
    2
    245 - 448
    1 - 204
    204
    4
    3
    449 - 750
    398 - 699
    302
    5
    4
    751 - 1003
    1879 - 2131
    253
    6
    5
    1004 - 1266
    1167 - 1429
    263
    7
    6
    1267 - 1489
    700 - 922
    1 - 223
    223
    8
    7
    1490 - 1698
    1430 - 1638
    209
    9
    8
    1699 - 1938
    1639 - 1878
    224 - 463
    240
    10
    9
    1939 - 2126
    2132 - 2319
    188
    11
    10
    2127 - 2319
    205 - 397
    193
    Worksheet: Sheet1


    here below a few more runs, showing just column G
    _____ Workbook: Sample.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    G
    1
    2
    591 - 834
    3
    835 - 1038
    4
    1502 - 1803
    5
    2067 - 2319
    6
    1804 - 2066
    7
    1279 - 1501
    8
    382 - 590
    9
    1039 - 1278
    10
    194 - 381
    11
    1 - 193
    Worksheet: Sheet1

    _____ Workbook: Sample.xlsm ( Using Excel 2007 32 bit )
    254 - 497
    2076 - 2319
    1470 - 1713
    638 - 881
    498 - 701
    517 - 720
    1923 - 2126
    1 - 204
    1174 - 1475
    1774 - 2075
    705 - 1006
    2018 - 2319
    1 - 253
    264 - 516
    264 - 516
    1354 - 1606
    911 - 1173
    1 - 263
    1 - 263
    882 - 1144
    1476 - 1698
    1551 - 1773
    1247 - 1469
    1607 - 1829
    702 - 910
    1342 - 1550
    1714 - 1922
    1145 - 1353
    1892 - 2131
    721 - 960
    1007 - 1246
    205 - 444
    2132 - 2319
    1154 - 1341
    517 - 704
    1830 - 2017
    1699 - 1891
    961 - 1153
    2127 - 2319
    445 - 637
    Worksheet: Sheet1
    Attached Files Attached Files

Similar Threads

  1. Notes tests, Scrapping, YouTube
    By DocAElstein in forum Test Area
    Replies: 221
    Last Post: 10-02-2022, 06:21 PM
  2. Gif Image Video stuff testies
    By DocAElstein in forum Test Area
    Replies: 13
    Last Post: 09-06-2021, 01:07 PM
  3. Test excelfox Corruptions January 2021 *
    By DocAElstein in forum Test Area
    Replies: 13
    Last Post: 01-25-2021, 08:07 PM
  4. Replies: 161
    Last Post: 04-24-2019, 11:47 AM
  5. Replies: 8
    Last Post: 08-17-2013, 02:42 PM

Posting Permissions

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