Page 92 of 94 FirstFirst ... 42829091929394 LastLast
Results 911 to 920 of 935

Thread: Windows 10 and Office Excel

  1. #911
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    Hi
    I can’t help directly as I have little experience with Microsoft Word.
    We do not have many Word VBA experts looking in to excelfox

    However, I can tell you that the Author of that code, HansV, is quite active posting at Eileen’s Lounge, https://eileenslounge.com/app.php/portal

    Here is the link to the Word Sub Forum there:
    https://eileenslounge.com/viewforum.php?f=26

    You may be able to get help from that forum, if you join and post your question there
    If you decide to ask for help there, then I would suggest that you prepare and upload a Word File document example, and explain clearly exactly what you want the coding to do.

    ( Remember to tell them that you have also posted here:
    You must tell them, that you have also posted the same question at excelfox: Give them this link to your post here:
    https://excelfox.com/forum/showthread.php/2786-VBA-Copy-Tables-from-Word-to-Excel )



    Alan

  2. #912
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    Hi
    I am not sure what hte problem is with the download for you. Once in a while something wont download on a particular operating system or Browser. We never figured out why yet.
    I just put it in a share place for you, perhaps that will work for you
    Share ‘Work_file.xlsm’ https://app.box.com/s/v9ifgeicp6nzha0axcha3qcprzgprgob

    It's difficult for me to help further beacuse
    _1 I can't see anything on the userform - as i showed in the screen shot the text and numbers are too small to see,
    _ 2 I still really don't know what should happen.I don't understand what you want, where data comes from etc. etc... - You have given a pefectly good explanation for yourself or anyone else maybe who knows already the sort of thing that you are doing.
    But you are talking to a complee stranger that knows VBA quite well but has no idea of your work. (and hasn't done much with userforms either - I do understand the very basics of them). I expect it would take me 10 seconds to sort your problem out , but a day first before I figured out what it is that should happen.
    You will always improve your chances of an answer here, or elsewhere, if you give a very detailed walkthrough of what should happen , giving sample data and saying exactly what steps you do, where the data is coming from etc. etc
    I feel your pain. You have an annoying problem and want the answer quick. Sometimes you strike lucky, and find someone that has done almost excactly what you are doing and sees at a glance what the problem is.
    I hav'nt, so I can't

    Alan
    ….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. #913
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    Hi
    OK, that’s all a bit clearer for me, thanks.
    I probably could have a go… But

    I am still having problems doing anything with your UserForm.
    I tried on three different computers, with Excel versions 2007, 2010 and 2013(professional)

    So, I press the Form Button

    This happens:
    Excel 2007 text is too small to do anything with, as before ( that I did before was on another computer which also had Excel 2007 )



    Excel 2010 error


    Excel 2013 ( Professional ) error



    Translating those error texts in the last two screenshots to English – it says something about not being able to set ColumnWidth property due to type mismatch




    If nobody else helps you in the meantime, I will try and take a look again later today when I have more time. I might be able to do something in Excel 2007, but its going to be very difficult for me to try and add data in the UserForm as I can barely see anything.

    Its very strange that I get those errors in newer Excel versions. Also the small size I see, could suggest, along with the errors in newer versions, that something is dodgy with your userform


    What Excel version are you using?


    Perhaps in the meantime you could take a look and see if you can do something with the UserForm. Maybe make something bigger , at least just temporarily. Maybe if you make the Form and / or the text bigger and upload some other files with a modified UserForm size in, then I might have a better chance of seeing something in it.
    And/ or see if you can figure out why I can't get the UserForm to come up in some of my Excels.
    As I mentined, I do not have much experience with UserForms, but I have made a few. So far, when they work, they work in all my Excel versions. So I think there is at least a chance that something is a bit wonky in your UserForm, something that just by chance allows it work, all be it with very small text, in Excel 2007.
    Could be a totally other explanation. I am just geussing due to my lack of a lot of experience with UserForms

    I will try and look again today. It might have to wait until tomorrow.
    Please if you get it fixed in the meantime, let me know, so I don’t waste my time.

    Thanks
    Alan

  4. #914
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    Hi Liviu

    OK, I done it for you. ( It was not really solving a problem in your coding. There was no coding anywhere that made any attempt to put data into worksheet Database1 )
    I have basically added / incorporated coding of the form I had in Sub MatchNameProjectTask3() into your macro to do the extra filling of Database1
    So your initial explanation in post #1 was a bit misleading.
    No matter
    Here is the solution(s)


    Some minor issues first
    _ The userFormtext size is very good now. But the Form size was a bit big and bloated. But I fiddled around a bit (blindly) in the UserForm properties and in Private Sub UserForm_Initialize(). So that’s good enough for me to work with
    _ I figured out that strange error as well in the .ColumnWidths : I am mostly using German Excel and my list separator is sometimes taken as ; rather than a ,
    I did a quick bodge to get over that, but you might want to put that back to as you had it.
    Code:
            ' Quick dodge to get over problem of different seperators in different land Office versions
            On Error Resume Next
            .LstDatabase.ColumnWidths = "40;50;60;60;60;60;60;30"
            .LstDatabase.ColumnWidths = "40,50,60,60,60,60,60,30"
            On Error GoTo 0
            If iRow > 1 Then
    It is usually better to do this sort of thing withput error handling, but I did not know how to easilly determine the seperator used by any Excel. I might be able later to do something along the lines that I did here: https://eileenslounge.com/viewtopic....290229#p290229 https://eileenslounge.com/viewtopic....267466#p267466
    Possibly someone else passing this Thread knows of a simpler way.? I wpuld be very intersted and grateful of any imput



    So on now to the main stuff

    This is approximately the macro you uploaded which need the additions
    Code:
    Dim sh As Worksheet
    Dim sh1 As Worksheet
    Dim iRow As Long, colno As Integer, iCol As Long, rowno As Integer
    Dim iRow1 As Long, colno1 As Integer, iCol1 As Integer, reqdRow As Integer
    Set sh = ThisWorkbook.Sheets("Database")
    Set sh1 = ThisWorkbook.Sheets("Database1")
    iRow = [Counta(Database!A:A)] + 1
    iCol = Sheets("Database").Cells(1, Columns.Count).End(xlToLeft).Column - 1
    iRow1 = [Counta(Database1!A:A)] + 1
    iCol1 = Sheets("Database1").Cells(1, Columns.Count).End(xlToLeft).Column - 1
        With sh
            .Cells(iRow, 1) = iRow - 1
            .Cells(iRow, 2) = UserFormTest.CmbYear.Value
            .Cells(iRow, 3) = UserFormTest.CmbMonth.Value
            .Cells(iRow, 4) = UserFormTest.CmbName.Value
            .Cells(iRow, 5) = UserFormTest.CmbProject.Value
            .Cells(iRow, 6) = UserFormTest.CmbTask.Value
            .Cells(iRow, 7) = UserFormTest.TxtAmount.Value
            .Cells(iRow, 8) = Application.UserName
        End With
        Call Reset
    MsgBox "Date incarcate cu succes!"
    End Sub
    


    This next is that macro with the addition. The additions are based on my last macro Sub MatchNameProjectTask3()

    Code:
    Sub Submit_Data()
    Dim Wsh As Worksheet
    Dim Wsh1 As Worksheet
    Dim iRow As Long, colno As Integer, iCol As Long, rowno As Integer
    Dim iRow1 As Long, colno1 As Integer, iCol1 As Integer, reqdRow As Integer
    Set Wsh = ThisWorkbook.Sheets("Database"): Wsh.Select
    Set Wsh1 = ThisWorkbook.Sheets("Database1")
    iRow = [Counta(Database!A:A)] + 1
                                      'Dim LrD As Long: Let LrD = iRow - 1
    iCol = Sheets("Database").Cells(1, Columns.Count).End(xlToLeft).Column - 1
    iRow1 = [Counta(Database1!A:A)] + 1
    iCol1 = Sheets("Database1").Cells(1, Columns.Count).End(xlToLeft).Column - 1
        With Wsh
            .Cells(iRow, 1) = iRow - 1
            .Cells(iRow, 2) = UserFormTest.CmbYear.Value ' Year
            .Cells(iRow, 3) = UserFormTest.CmbMonth.Value ' Month
            .Cells(iRow, 4) = UserFormTest.CmbName.Value ' Name
            .Cells(iRow, 5) = UserFormTest.CmbProject.Value ' Project
            .Cells(iRow, 6) = UserFormTest.CmbTask.Value ' Task
            .Cells(iRow, 7) = UserFormTest.TxtAmount.Value ' Amount
            .Cells(iRow, 8) = Application.UserName ' Submit
        End With
    ' the bit to put Amount on Database1
    Rem 2a  match Name and Project and Task
        With UserFormTest
        Dim Kee As String: Let Kee = .CmbName.Value & .CmbProject.Value & .CmbTask.Value
        End With
    Dim LrD1 As Long: Let LrD1 = Wsh1.Range("A" & Wsh1.Rows.Count & "").End(xlUp).Row
    Dim arrD1() As String: ReDim arrD1(2 To LrD1)
    Dim rwD1 As Long
        For rwD1 = 2 To LrD1
         Let arrD1(rwD1) = Wsh1.Range("A" & rwD1 & "") & Wsh1.Range("B" & rwD1 & "") & Wsh1.Range("C" & rwD1 & "")
        Next rwD1
    '2b) Array of date serials from Database1
    Dim arrDtSerials() As Variant, LcD1 As Long
     Let LcD1 = Wsh1.Cells(1, Wsh1.Columns.Count).End(xlToLeft).Column
     Let arrDtSerials() = Wsh1.Range("A1").Resize(1, LcD1).Value2
    Rem 3 compare arrays for headings
        For rwD1 = 2 To LrD1
            If Kee = arrD1(rwD1) Then    '     MsgBox prompt:="match for " & Kee & " at Database1 row " & rwD1
            '3b We have a heading match , so now match the date
            Dim DteSerial As Variant
            ' Let DteSerial = WsD.Evaluate("=DATEVALUE(""1 " & WsD.Range("C2").Value & " " & WsD.Range("B2").Value & """)")
            ' Let DteSerial = Wsh.Evaluate("=DATEVALUE(""1 " & Wsh.Range("C" & rwD & "").Value & " " & WsD.Range("B" & rwD & "").Value & """)")
             Let DteSerial = Wsh.Evaluate("=DATEVALUE(""1 " & Wsh.Range("C" & iRow & "").Value & " " & Wsh.Range("B" & iRow & "").Value & """)")
            Dim MtchRes As Variant
             Let MtchRes = Application.match(DteSerial, arrDtSerials(), 0)
                If IsError(MtchRes) Then MsgBox prompt:="No date match": Exit Sub
             'Let Wsh1.Cells(rwD1, MtchRes) = WsD.Range("G" & rwD & "").Value
             Wsh1.Activate
             Let Wsh1.Cells(rwD1, MtchRes) = Wsh.Range("G" & iRow & "").Value
            Else
            
            End If
        Next rwD1
    Call Reset
    MsgBox "Date incarcate cu succes!"
    End Sub
    


    The uploaded file, Work_file_modifiedBefore.xlsm is approximately your original uploaded (modified ) file.
    , and Work_file_modifiedAfter.xlsm, is that same file with the modified macro


    If anything is not quite right, then let me know and I will take another look. but you will have to wait a few days

    Alan






    Files at share site, incase you can’t get them from the upload again:
    Share ‘Work_file_modifiedBefore.xlsm’ https://app.box.com/s/szruzgnhmccgwm3v9o8iafz9s29p182a
    Share ‘Work_file_modifiedAfter.xlsm’ https://app.box.com/s/wigzth8u6khlwpqmtqj5eb1u6gqpwc2z


    Attached Files Attached Files
    ….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. #915
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    Your welcome, thanks for the feedback
    It is always very difficult to explain to someone else in enough detail for them to understand. It is also very difficult if you do not speak the English language.
    But a good detailed walkthrough explanation will always make it easier for you to get help.

    Alan


    ( P.S. Another thing that may help you get help in the future:
    It is some times courteous to tell the people at mrexcel.com that you have a solution, and tell them where you got it. That would help anyone seeing that Thread in the future at mrexcel.com that is looking for a similar solution.
    Being courteous like that may also help you to get help from mrexcel.com in the future.

    But that is not too important)
    ….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. #916
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    Hello Amelynn
    Welcome to ExcelFox , the thinking man’s Excel forum


    Quote Originally Posted by Amelynn View Post
    Who can help me, ....
    I think, therefore I am , and able to help you.

    Quote Originally Posted by Amelynn View Post
    ...... I don't understand how the line ".List
    = Application.Index(rng, Evaluate("ROW(1:" & rng.Rows.Count & ")"), Array(1, 3))
    " works and I can't stay So....
    To Explain

    Question: _(i) What is Array(1, 3) ?
    Answer_ It is like –
    ___1 _3
    ( Sometime we write in excel spreadsheet convention {1, 3} , but this usually means the same thing )

    Question: _(ii)a) Evaluate("ROW(1:" & rng.Rows.Count & ")")
    Answer:
    Quote Originally Posted by Amelynn View Post
    ..... evaluate (…….. used to occupy excel formulas in vba) with row,
    Correct! Good! - Because you understand this, it makes the explanation for me much easier.
    We are really only interested in understanding what is , =ROW(1:" & rng.Rows.Count & ")" , in excel spreadsheet formula

    Question: _(ii)b) What is =ROW(1:" & rng.Rows.Count & ") ? ( in excel spreadsheet )
    For your range, rng = B4:D8 , rng.Rows.Count = 5
    =ROW(1: " & rng.Rows.Count & " )
    =ROW(1: " & 5 & " )
    =ROW(1:5)

    ( Green is Excel Spreadsheet, Blue is VBA in string “ “ in Evaluate( “ “ ) )


    The excel spreadsheet Row( ) function is usually like for
    Row( A1) = 1
    but can also return a “vertical” array of values like
    Row( A1:A2) = 1
    Row( A1:A2) = 2
    Inside VBA Evaluate _ we find that we are decoupled from spreadsheet absolute values, and so in inside VBA Evaluate _
    Row(A1:A2) = Row( 1:2) = 1
    Row(A1:A2) = Row( 1:2) = 2

    ROW(1:5)
    It is like
    1
    2
    3
    4
    5

    ( Sometimes we may write
    {1
    2
    3
    4
    5}

    or sometimes we may write in excel spreadsheet convention , ={1;2;3;4;5} , but usually this means the same thing
    )
    Note: For “vertical” array some excel use ; but some Excel use \ – So sometime you may need ={1\2\3\4\5}




    Sometimes if we are lucky, Excel will try to do array calculations and return you an array.
    Like
    Code:
    	{	1	2		X	{	6	8		  =	{	1, 6	2, 8	
    		3	4	}			7	9	}			3, 7	4, 9	}
    But if you ask it to do = Index ___ , ROW(1:5)_ ,_ Array{1 , 3} it tries to look at columns and rows not specified.
    This should not work
    Code:
    =  {	1	?			   {	1	3	
    	2	?				?	?	
    	3	?		X		?	?	
    	4	?				?	?	
    	5	?	}			?	?	}
    ???? So we have a problem ?,
    But we can be lucky again, because then Excel will guess to see the following instead, ( actually its more complicated then that, more precisely it is due to Excel VBA Interception and Implicit Intersection , but we often say that Excel guesses things, as its often written to get things correct when you miss things out. ( In this particular case it is not clear if the phenomenum occurs by accident or design ) )
    Code:
    =  {	1	1			   {	1	3	
    	2	2				1	3	
    	3	3		X		1	3	
    	4	4				1	3	
    	5	5	}			1	3	}
    ( What is actually happening there above in those last two sketches is: -
    If Excel is given a single row or a single column, but is being required to look at values of further adjoining rows and columns where no values are given, then the effect of the phenomena of Excel VBA Interception and Implicit Intersection is that in certain situation the missing values will effectively be taken as a duplication of the values in the given row or column
    )

    So, Index will try to give us
    Code:
    _______    Index(    (    ,	1, 1	1, 3	
    				2, 1	2, 3	
    				3, 1	3, 3	
    				4, 1	4, 3	
    				5, 1	5, 3	  )
    So if your range is, rng = B4:D8
    -__=
    Code:
    	_B4	_C4	_D4
    	_B5	_C5	_D5
    	_B6	_C6	_D6
    	_B7	_C7	_D7
    	_B8	_C8	_D8
    then Application.Index(rng, Evaluate("=ROW(1:" & rng.Rows.Count & ")"), Array(1, 3))
    -__ =Application.Index(rng, Evaluate("=ROW(1:5)"), Array(1, 3))
    -__ =Application.Index(rng, Evaluate("={1;2;3;4;5}"), Array(1, 3))
    -__ =Application.Index(rng, Evaluate("={1;2;3;4;5}"), Evaluate("={1, 3}"))

    -__ =
    Code:
        rng  ,            1,1  1,3
                          2,1  2,3
                          3,1  3,3
                          4,1  4,3
                          5,1  5,3
    -__=
    Code:
        _B4 _C4 _D4       1,1  1,3
        _B5 _C5 _D5       2,1  2,3
        _B6 _C6 _D6       3,1  3,3
        _B7 _C7 _D7       4,1  4,3
        _B8 _C8 _D8       5,1  5,3
    Code:
    	  =     _B4	_D4
    		_B5	_D5
    		_B6	_D6
    		_B7	_D7
    		_B8	_D8


    Quote Originally Posted by Amelynn View Post
    ........use an array to determine the rows as well......
    Sure, this is no problem:
    One way, for example, for just 1st 3rd and 5th row
    Change
    Evaluate("={1;2;3;4;5}")
    to
    Evaluate("={1;3;5}")

    -__ =Application.Index(rng, Evaluate("={1;3;5}"), Array(1, 3))
    -__ =Application.Index(rng, Evaluate("={1;3;5}"), Evaluate("={1, 3}"))

    Code:
        _B4 _C4 _D4       1,1  1,3
        _B5 _C5 _D5       3,1  3,3
        _B6 _C6 _D6       5,1  5,3
        _B7 _C7 _D7
        _B8 _C8 _D8
    Code:
    	  =     _B4	_D4
    		_B6	_D6
    		_B8	_D8



    Here a demo macro for you
    Put some arbitrary values in your range "B4:D8" , then run this macro:
    Code:
    Sub Test()
    Dim Rng As Range
     Set Rng = Worksheets("Sheet1").Range("B4:D8")
    Dim RwsCnt As Long
     Let RwsCnt = Rng.Rows.Count '  is = 5
    
    Dim arr_List() As Variant
     Let arr_List() = Application.Index(Rng, Evaluate("=ROW(1:" & Rng.Rows.Count & ")"), Array(1, 3))
     Let arr_List() = Application.Index(Rng, Evaluate("=ROW(1:" & RwsCnt & ")"), Array(1, 3))
     Let arr_List() = Application.Index(Rng, Evaluate("=ROW(1:5)"), Array(1, 3))
     Let arr_List() = Application.Index(Rng, Evaluate("={1;2;3;4;5}"), Array(1, 3))
     Let arr_List() = Application.Index(Rng, Evaluate("={1;2;3;4;5}"), Evaluate("={1,3}"))
    
     Let Worksheets("Sheet1").Range("A40").Resize(UBound(arr_List(), 1), UBound(arr_List(), 2)).Value = arr_List()
    
    ' To only select 1st 3rd and 5th row
     Let arr_List() = Application.Index(Rng, Evaluate("={1;3;5}"), Evaluate("={1,3}"))
     Let Worksheets("Sheet1").Range("A47").Resize(UBound(arr_List(), 1), UBound(arr_List(), 2)).Value = arr_List()
    
    End Sub



    Alan
    Attached Files Attached Files
    ….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. #917
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10

    Windows 10 and Office Excel

    URL links to here: This is post: https://excelfox.com/forum/showthrea...ll=1#post16456
    https://excelfox.com/forum/showthread.php/2789-Item-way-of-thinking-as-alternative-to-conventional-row-column-looping?p=16456&viewfull=1#post16456
    https://excelfox.com/forum/showthrea...column-looping
    https://excelfox.com/forum/showthread.php/2789-Item-way-of-thinking-as-alternative-to-conventional-row-column-looping
    https://excelfox.com/forum/showthrea...-looping#post1
    https://excelfox.com/forum/showthread.php/2789-Item-way-of-thinking-as-alternative-to-conventional-row-column-looping#post1





    Item way of thinking as alternative to conventional row column looping


    Current conventional way of thinking
    This Blog post assumes that you have some basic Excel VBA programming experience, and that you are familiar with this general idea used typically when filling or getting data from cells
    __For Rw = 1 To maximumRows
    ____For Clm = 1 To maximumColumns
    _____( Rw, Clm )
    ____Next Clm
    __ Next Rw

    This basic process you should make sure you fully understand before reading further.
    This Blog post suggest a slightly different way about thinking about that process

    Introduction
    Excel Spreadsheets can be turned into pretty pictures, computer graphics and games and “dashboards”.
    But they are usually not the best at doing those things.
    They are best for doing things with 2 dimensional “tables” of data.
    They bridge the gap between
    _ dead stores of data or long fast streams of string data,
    and
    _ relatively slow and static living humans interacting with them

    I expect we are not a long way from interacting in a 3 dimensional way, but it will settle down, I think, to be useful in a limited way. More than 3 dimensions are difficult for humans to react easily with.
    A 2 dimensional desktop is particularly convenient for us.
    Smartphones are a trend that I think might go back a bit to being just glorified telephones, walkmans, live cameras and simple computer games.

    We are basically talking in this Thread about organising a string of data travelling at the speed of light into a static line or row of the data, then carrying the rest of the data back, feeding in another row or line or “going down”, then doing the same again.

    I think for Excel formulas and VBA we should not take the core of the thinking much further than this.
    For furthering the study and manipulation of static table data something else , another concept, such as Power Query / Get and Transform might be more appropriate.

    Looping along columns for every row The conventional way
    __For Rw = 1 To maximumRows
    ____For Clm = 1 To maximumColumns
    _____( Rw, Clm )
    ____Next Clm
    __ Next Rw

    This is what we have got used to, from reading books, to the workings of old printers, to how a screen is filed with data. It is an efficient and logical consequence that a spreadsheet, or a rectangular range in a spreadsheet, is filled and otherwise updated in the same way.
    Usually we look at a cell when doing formula calculations, but if we increase the exposed area during a screen update, we can get an efficient, almost simultaneous, calculation across an entire range. This latter is the basis of the workings of the so called array formulas, ( “CSE” stuff ). We will come on to that in the next post

    Looping the Items
    Many things in VBA, and computers generally, are actually ordered somewhere by something similar to a unique item number , 1 2 3 4 5 6 … etc. ( Note: in some computer conventions the first may start at 0 so we have 0 1 2 3 4 5… etc. )
    Conventionally, the Range Item numbers are also so organised, and further follow the generally accepted convention of
    Across
    _____down
    back

    Across
    _____down
    back

    ………etc
    .

    ( Conventionally in computer stream strings we may refer to those
    backs as carriage returns, vbCr ,
    and
    the downs as line feeds, vbLf.
    These may be referred to as “invisible characters”, as we do not typically see them, but they must be there in the electronic string stream to indicate the start of a new line or new row
    )

    For example for a 2 row x 3 column range, this is where the item numbers are/ what cells the item number refers to
    1 2 3 vbCr & vbLf
    4 5 6

    Furthermore, for many things that do not have such an item number they may have a consistent order such that we can assume or assign some simple count mechanism to give them an index that we can use in a similar way to the Item number

    The crux of my suggestion in this Thread is to think of the basic process shown at the start of this Blog, in a slightly different way.
    A couple of reasons I can think of for doing this
    _ It may be helpful to think back to the more fundamental single string idea of what computers are, as the table type arrangement is only an interface for us, and is less representative of what is actually going on in a computer
    _ In some situations the alternative looping may have some advantages. For example we would not be limited to a rectangular range.

    Some simple required maths
    What we want to do is this sort of thing as an alternative to the basic process
    __For Itm = 1 To maximumItems
    ___( Row, Column)
    __Next Itm

    Before looking at the actual solution, lets simply put in words a simple solution idea, and consider again a 2 row, 3 column range
    1 2 3
    4 5 6

    In this case, our maximumRows will be 2 and the maximumColumns will be 3
    We have those sequentially numbers, and we want to convert then to row and column indices that would give us that spreadsheet range.

    Row Number from Item Number
    If we were to divide the actual item number by the maximumColumns , 3 , and take the integer of the result we would almost be there. But that would actually give us
    0 0 1
    1 1 2

    If we were to first subtract 1 from the Item number, then do the same again, divide that modified number by the maximumColumns , 3, and take the integer of the result we would have,
    Integer ( ( ItmNumber -1 ) / maximumColumns ) =
    0 0 0
    1 1 1

    So we now see that we only have to add 1 to the final results and we have the row number what we want.
    RowNumber = [ Integer ( ( ItmNumber -1 ) / maximumColumns ) ] + 1
    1 1 1
    2 2 2


    Column Number from Item Number
    This is slightly more tricky. But not much. I do this second as we need some of the ideas from the previous maths.
    An observation:
    To get the column number from the item number, the second row needs to be reduce by 1 x maximumColumns , and
    if we had a third row the item number would need to be reduced by 2 x maximumColumns … and so on.
    Note also, that it also fits this same logic to apply a reduction of 0 x maximumColumns to the first row.
    So we are looking for a multiplication factor based on the Item number which gives us that sort of number sequence like 0 0 0 ; 1 1 1 ; 2 2 2 etc. sequence
    We can see from one of the stages in the maths from the last section where we determined the row from the item number, that we did actually already have it:
    It was at this stage: -
    __________________Integer ( ( ItmNumber -1 ) / maximumColumns )
    ___=___0 0 0
    _______1 1 1

    and that would have further gone on for more rows to
    0 0 0 ; 1 1 1 ; 2 2 2 ; 3 3 3 … etc.

    So we can see one formula possibility:
    ItemNumber - [ Integer ( ( ItmNumber -1 ) / maximumColumns ) X maximumColumns ]
    This would result in our required column Indicies of
    1 2 3
    1 2 3


    _.______

    Simple VBA macro examples
    Code:
    Sub ItmNumbersLoopToRng()
    Dim Ws1 As Worksheet: Set Ws1 = ThisWorkbook.Worksheets("Sheet1")
    Dim ItmIndx As Long
    Dim maxClms As Long, maxRws As Long: Let maxClms = 3: Let maxRws = 2
        For ItmIndx = 1 To 5
        Dim Rw As Long, Clm As Long
         Let Rw = Int((ItmIndx - 1) / maxClms) + 1
         Let Clm = ItmIndx - (Int((ItmIndx - 1) / maxClms) * maxClms)
         Let Ws1.Cells.Item(Rw, Clm).Value = " (" & Rw & ", " & Clm & ")"
        Next ItmIndx
    End Sub
    
    Sub ItmNumbersLoopToRng2()
    Dim Ws1 As Worksheet: Set Ws1 = ThisWorkbook.Worksheets("Sheet1")
    Dim ItmIndx As Long
    Dim maxClms As Long, maxRws As Long: Let maxClms = 3: Let maxRws = 2
        For ItmIndx = 1 To 5
                        '    Dim Rw As Long, Clm As Long
                        '     Let Rw = Int((ItmIndx - 1) / maxClms) + 1
                        '     Let Clm = ItmIndx - (Int((ItmIndx - 1) / maxClms) * maxClms) 
         Let Ws1.Cells.Item(Int((ItmIndx - 1) / maxClms) + 1, ItmIndx - (Int((ItmIndx - 1) / maxClms) * maxClms)).Value = " (" & Int((ItmIndx - 1) / maxClms) + 1 & ", " & ItmIndx - (Int((ItmIndx - 1) / maxClms) * maxClms) & ")"
        Next ItmIndx
    End Sub
    
    __Result:_____
    _____ Workbook: OekyDoekyAmelynn.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    1
    (1, 1) (1, 2) (1, 3)
    2
    (2, 1) (2, 2)
    3
    Worksheet: Sheet1
    _.____


    ….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. #918
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    There is one interesting observation already that may help us understand some of the secret workings of Excel:
    Note that we have not needed to use the parameter of maximumRows
    Now, Consider a range object of 3 columns x 2 rows anywhere in a spreadsheet
    x x x vbCr & vbLf
    x x x

    Reasonably we would say that has 6 items, and conventionally we have, and we could confirm by experiment, that we have item 6 as shown here, X:
    x x x vbCr & vbLf
    x x X

    What is somewhat surprising perhaps, is that we can go on to reference any further item without causing any errors, and we remain in the maximum columns restriction but seem to have no limit, ( within reason ), in the rows.
    For example, referring to item 12, would get us here X:
    x x x vbCr & vbLf
    x x x
    vbCr & vbLf
    x x x vbCr & vbLf
    x x
    X

    This could be by design, or might just be an accident due to some internal calculations having a similar form to those I have suggested and discussed, - those that do not have any consideration of maximum row




    I intend adding some further post on this thread later to discuss the ideas and develop them further.

  9. #919
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    In support of these issues
    https://excelfox.com/forum/showthrea...ge51#post12784 https://www.youtube.com/watch?v=dKM8ZScbic8&t=75s
    Winget issues https://github.com/ChrisTitusTech/wi...770ae56d3b6e85
    https://github.com/ChrisTitusTech/wi...b236f3ecf290db

    06.07.2021 The Best Windows Utility ( second nice shade of grey GUI )
    Code:
    Write-Host "Checking winget..."
    
    Try{
    	# Check if winget is already installed
    	$er = (invoke-expression "winget -v") 2>&1
    	if ($lastexitcode) {throw $er}
    	Write-Host "winget is already installed."
    }
    Catch{
    	# winget is not installed. Install it from the Github release
    	Write-Host "winget is not found, installing it right now."
    	
    	$download = "https://github.com/microsoft/winget-cli/releases/download/v1.0.11692/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
    	$output = $PSScriptRoot + "\winget-latest.appxbundle"
    	Write-Host "Dowloading latest release"
    	Invoke-WebRequest -Uri $download -OutFile $output
    	
    	Write-Host "Installing the package"
    	Add-AppxPackage -Path $output
    }
    Finally {
    	# Start installing the packages with winget
    	#Get-Content .\winget.txt | ForEach-Object {
    	#	iex ("winget install -e " + $_)
    	#}
    }


    The Ultimate Windows Utility Upgrade 29 09 2021
    Code:
    Write-Host "Checking winget..."
    
    Try{
    	# Check if winget is already installed
    	$er = (invoke-expression "winget -v") 2>&1
    	if ($lastexitcode) {throw $er}
    	Write-Host "winget is already installed."
    }
    Catch{
    	# winget is not installed. Install it from the Microsoft Store
    	Write-Host "winget is not found, installing it right now."
    
    	Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget"
    	$nid = (Get-Process AppInstaller).id
    	Wait-Process -Id $nid
    
    }
    Finally {
    	# Start installing the packages with winget
    	#Get-Content .\winget.txt | ForEach-Object {
    	#	iex ("winget install -e " + $_)
    	#}
    }
    A commit a bit later by mrhaydendp to simplify a bit https://github.com/ChrisTitusTech/wi...0db?diff=split
    Code:
    Write-Host "Checking winget..."
    
    # Check if winget is installed
    if (Test-Path ~\AppData\Local\Microsoft\WindowsApps\winget.exe){
        'Winget Already Installed'
    }  
    else{
        # Installing winget from the Microsoft Store
    	Write-Host "Winget not found, installing it now."
    	Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget"
    	$nid = (Get-Process AppInstaller).Id
    	Wait-Process -Id $nid
    	Write-Host Winget Installed
    }

  10. #920
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    In support of these issues
    https://excelfox.com/forum/showthrea...ge51#post12784 https://www.youtube.com/watch?v=dKM8ZScbic8&t=75s
    Winget issues https://github.com/ChrisTitusTech/wi...770ae56d3b6e85
    https://github.com/ChrisTitusTech/wi...b236f3ecf290db

    06.07.2021 The Best Windows Utility ( second nice shade of grey GUI )
    Code:
    Write-Host "Checking winget..."
    
    Try{
    	# Check if winget is already installed
    	$er = (invoke-expression "winget -v") 2>&1
    	if ($lastexitcode) {throw $er}
    	Write-Host "winget is already installed."
    }
    Catch{
    	# winget is not installed. Install it from the Github release
    	Write-Host "winget is not found, installing it right now."
    	
    	$download = "https://github.com/microsoft/winget-cli/releases/download/v1.0.11692/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
    	$output = $PSScriptRoot + "\winget-latest.appxbundle"
    	Write-Host "Dowloading latest release"
    	Invoke-WebRequest -Uri $download -OutFile $output
    	
    	Write-Host "Installing the package"
    	Add-AppxPackage -Path $output
    }
    Finally {
    	# Start installing the packages with winget
    	#Get-Content .\winget.txt | ForEach-Object {
    	#	iex ("winget install -e " + $_)
    	#}
    }


    The Ultimate Windows Utility Upgrade 29 09 2021
    Code:
    Write-Host "Checking winget..."
    
    Try{
    	# Check if winget is already installed
    	$er = (invoke-expression "winget -v") 2>&1
    	if ($lastexitcode) {throw $er}
    	Write-Host "winget is already installed."
    }
    Catch{
    	# winget is not installed. Install it from the Microsoft Store
    	Write-Host "winget is not found, installing it right now."
    
    	Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget"
    	$nid = (Get-Process AppInstaller).id
    	Wait-Process -Id $nid
    
    }
    Finally {
    	# Start installing the packages with winget
    	#Get-Content .\winget.txt | ForEach-Object {
    	#	iex ("winget install -e " + $_)
    	#}
    }
    A commit a bit later by mrhaydendp to simplify a bit https://github.com/ChrisTitusTech/wi...0db?diff=split
    Code:
    Write-Host "Checking winget..."
    
    # Check if winget is installed
    if (Test-Path ~\AppData\Local\Microsoft\WindowsApps\winget.exe){
        'Winget Already Installed'
    }  
    else{
        # Installing winget from the Microsoft Store
    	Write-Host "Winget not found, installing it now."
    	Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget"
    	$nid = (Get-Process AppInstaller).Id
    	Wait-Process -Id $nid
    	Write-Host Winget Installed
    }

Similar Threads

  1. Tests and Notes on Range Referrencing
    By DocAElstein in forum Test Area
    Replies: 70
    Last Post: 02-20-2024, 01:54 AM
  2. Tests and Notes for EMail Threads
    By DocAElstein in forum Test Area
    Replies: 29
    Last Post: 11-15-2022, 04:39 PM
  3. Replies: 49
    Last Post: 03-20-2018, 04:09 PM
  4. Notes tests. Excel VBA Folder File Search
    By DocAElstein in forum Test Area
    Replies: 39
    Last Post: 03-20-2018, 04:09 PM
  5. Replies: 2
    Last Post: 12-04-2012, 02:05 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
  •