PDA

View Full Version : Just testing a before a possible Thread post. No reply needed



DocAElstein
09-16-2015, 09:08 PM
Test test

_____ Workbook: ProAktuellex8600x2Sort1.xlsm ( Using Excel 2007 32 bit )
Row\Col
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X

16691
118

0.2

7.8

3.1

3.1

34





0.1


16692
123

0.2

7

8.7

8.5

30

0.1



0


16693
120

0.2

7.4

5.7

5.7

32

0



0.1


16694
123

0.2

7

8.9

8.9

30

0.1






16695
118

0.2

7.8

3.1

3.1

34

0

0

0.1


16696
123

0.2

7

8.9

8.9

30

0.1






16697
123

0.2

7

8.9

8.9

30

0.1






16698
119

0.2

7.5

5.1

5.1

33

0



0.1


16699
123

0.2

7

8.9

8.9

30

0.1






16700
123

0.2

7

8.9

8.9

30

0.1

0

0


16701
123

0.2

7

8.9

8.9

30

0.1






16702
123

0.2

7

8.9

8.9

30

0.1






16703
123

0.2

7

8.9

8.9

30

0.1






16704
117

0.2

7.7

3.1

3.1

34





0.1


16705
123

0.2

7

8.9

8.9

30

0.1






16706
117

0.2

7.8

3.1

3.1

34





0.1


16707
117

0.2

7.7

3.1

3.1

34





0.1


16708
120

0.2

6.9

8.4

8.4

30

0.1

0

0


16709
321

17

19

10

1.8

24

0



0.3


16710
121

0.2

6.9

8.8

8.8

30

0.1






16711
300

6.8

29

16

8.7

17

0

0.3

0.1


16712
233

7.3

15

13

5.2

16

0.1



0


16713
186

0.8

19

12

11

28

0.1

0.2

0.1
Worksheet: Sheet1

DocAElstein
09-16-2015, 09:09 PM
Hi Jeff,
Why have you deleted this Thread_...
http://imgur.com/m17fPbU ( http://www.excelforum.com/hello-introduce-yourself/1175371-seeking-your-thoughts.html )
_.. which you started?, as well as my Reply:




I guess I know the answer, but doesn't mean I actually want to do it, especially to a member with so many years, posts, and the title of Forum Expert.
http://www.excelforum.com/excel-general/1175288-complicated-formula-needed.html
I know there shouldn't be any exceptions, but I suppose infractions are warranted!....
Hi Jeff, :)
I do not quite understand what you are asking?
( The OP said he was unable to change the Title. http://www.excelforum.com/excel-general/1175288-formula-to-calculate-cancellation-charges-due.html#post4591186 )

Are you suggesting that Special-K should be given an infractions for continuing after your Moderator's message?

If so I think the issue that needed to be addressed first is with the OP and why he is / was unable to change the Title. Just my Opinion.. I think you should have followed that up. http://www.excelforum.com/excel-general/1175288-formula-to-calculate-cancellation-charges-due.html#post4591186 Just my Opinion.. ***

But I do agree that a good title is very important. That is one rule that I do feel is very important.
_.....


***
_ Possibly the OP was posting at a time when there were software problems making editing difficult ( he mentions the dreaded spinning wheel that we all hate so much ).
Or
_ He is using one of the Forum styles other than default. Sometimes not all options are available in all styles:......
ForumStyles.JPG http://imgur.com/hKhyE8M
http://www.excelforum.com/the-water-cooler/1166938-dont-enter-whole-post-2.html#post4543964
http://www.excelforum.com/the-water-cooler/1166938-dont-enter-whole-post-3.html#post4543988
http://www.excelforum.com/the-water-cooler/1166938-dont-enter-whole-post-3.html#post4544280
_Also as a new OP -he may not yet be able to Edit posts!
duckersjNewOpIsMatey.JPG http://imgur.com/tTubchA
( I beleive such things may be restricted for new users to help prevent spammers joining and making a mess )


Alan


P.s. Do you realise that you are posting this http://www.excelforum.com/hello-introduce-yourself/1175371-seeking-your-thoughts.html in the Sub Forum (Off Topic) Hello..Introduce yourself ?
JeffHelloIntroduceInfractionsWonk.JPG http://imgur.com/m17fPbU
I do not think that is the appropriate Sub Forum. ( Probably Water Cooler or Suggestions for Improvement or Feedback / Comments / Suggestions etc. But just my opinion. I do not think you should receive an infraction for incorrect posting.. Lol... – Possibly just a negative reputation would do .. Lol... :) --- seeking anyone's thoughts ?? :)

DocAElstein
09-16-2015, 09:21 PM
Recursion Procedures in Excel VBA. Recursion technique in coding
Procedures Calling others
I think this can be very easy to understand. I think it has been made unnecessary hard to understand by two things:
_ (i) The usual initial explanation or definition : …. ..” A procedure that calls itself is a recursive procedure…” – forget that it is rubbish
_ (i) if you are familiar with stepping through a code in the VBEditor using F8 debug mode, ( http://www.eileenslounge.com/viewtopic.php?f=27&t=16407&p=247121#p247121 ) , then you might be confused into believing _ (i) if you step through coding which goes into recursion.

Procedures Calling others
A procedure ( also known as code , coding , or routine, or program ) is just a set of instruction which are followed when it “runs”
A procedure Calling another procedure is quite common in even simple programming. This just means that a running procedure has a code line that instructs another procedure to start. The technical term is that the original procedure Calls another.
What may not be immediately obvious, is that
_ a) generally VBA coding can only do one procedure at a time.
_ b) for a simple Calling of a procedure from another, the procedure doing the Calling will pause , whilst the Called procedure runs. When that Called procedure Ends , then the original paused procedure will carry on from the point where it paused, which will necessarily be the Call point

These points might not be so obvious by looking at the coding in the VB Editor window. For example, below is an initial code passing some information to a second procedure which it Calls
Those actual “procedures” are just instructions. You could consider those as your master copy, or on the other hand you might just consider them as one of many possible copies: There is nothing to stop you storing copies of all that all over the place, on computers, on paper etc… in any case, VBA will have made a note of where these instructions are. When you start the first code running, VBA will make a copy of the instructions ( Sub1 ) and run that. When VBA then reaches the code line Call Sub2(CpyNo:=StrtCpyNo, Msg:="Initial Message") , it will pause Sub1 , while it makes a copy of the second procedure instructions, Sub2 , and it will run through those instructions until they are finished, at which point it resumes Sub1 at the Call code line.

If you go unto the VBEditor ( Via keys Alt+F11 from Excel ) , then click anywhere in Sub1 and hit key F8 , then you will proceed in step mode through the coding. If you bear in mind the points _ a) and _ b) , then you might be able to follow and understand what is going on.

Option Explicit
Sub Sub1()
Dim StrtCpyNo As Long ' To count copy number of code instructions being run
Let StrtCpyNo = 1



Call Sub2(CpyNo:=StrtCpyNo, Msg:="Initial Message")

MsgBox Prompt:="Ending main procedure"
End Sub
' Code above is Main calling procedure_________________________________________ ________________________________________

' Code below is called procedure
Sub Sub2(ByVal CpyNo As Long, ByVal Msg As String)
Dim CopyNo As Long ' This is to indicate which copy of Sub2 is currently running
Let CopyNo = CpyNo
MsgBox Prompt:="You are Starting Sub2 , copy " & CopyNo

MsgBox Prompt:="You are Ending Sub2 , copy " & CopyNo
End Sub
Because the first routine pauses whilst the second routine is done, we could attempt to write the equivalent single routine, which progresses through the same steps, in the same order as when the above coding is run by starting Sub 1

Sub Sub1Sub2()
Dim StrtCpyNo As Long
Let StrtCpyNo = 1


'Call Sub2( CpyNo:=StrtCpyNo, Msg:="Initial Message")
' Sub 2
Dim CpyNo As Long: Let CpyNo = StrtCpyNo: Dim Msg As String: Let Msg = "Initial Message"
Dim CopyNo As Long
Let CopyNo = CpyNo
MsgBox Prompt:="You are Starting Sub2 , copy " & CopyNo

MsgBox Prompt:="You are Ending Sub2 , copy " & CopyNo
' End Sub2

MsgBox Prompt:="Ending main procedure"
End Sub

Some things to note, before moving onto recursion things.. :
_ It is very easy to loose track of where you are when procedures Call others. It is particularly difficult to keep track when you are stepping through coding experiencing recursion processes. The reason for this is the following: As mentioned, the written coding is just copies of instructions. If you are doing any sort of debugging, such as the step F8 mode, then Microsoft has decided to indicate for you where you are in the copies shown in the VB Editor. That is not too bad for the coding shown so far. The problem comes in a recursion process, where, in this case, our Sub2 “Calls itself”.
What would be sensible for Microsoft to do in that case would be to show you a new copy of Sub2 , and step you through that second copy. Unfortunately that does not occur. Instead it shows you going through the same copy of Sub2
Therefore as you go through such a recursion process you will never know in which copy you are running
_ Following on from the last point: I don’t think I have ever experienced using recursion routines where it has not been useful to have an integer variable which keeps track of what copy I am in. I would personally recommend always to have such a variable
In the coding shown so far, this is my variables CopyNo and CpyNo
So far they have always been 1, as I have only been running 1 copy of Sub2
As we proceed, it should be clear how we can arrange that the variable always has a number equal to the copy number of the second routine, Sub2 , which is currently running

DocAElstein
09-16-2015, 09:22 PM
I am thinking of an alternative approach, the idea being to reduce on the steps to reorganising the array at every swap stage.. the idea came from 2 things …

_1 The recursion routine is fed currently the row indices of the rows that need to be sorted.
_2 We can use the VBA Application.Index Method allows us to re sort an array “ in one go “ via a code line like , pseudo formula..

arrOut() = App.Indx( ArrIn() , {1;3;2} , {1,2,3} )
arrOut() = App.Indx( ArrIn() , row indices , column indicies )

The above code line would change an arrIn() like this …_
A b c
D e f
G h I
_ … to a given output in arrOut() like this:
A b c
G h I
D e f

So the idea is that we sort the indices values, and then re apply the formula above

At this stage I propose modifying the existing code so as to have a better chance of a direct comparison in performance.. Both will be then subject to similar general inefficiencies arising from the very opened out explicit form of the codings generally

Here the basic modifications for Sub SimpleArraySort7(__ , Sub TestieSimpleArraySort7()

Global Variables
To help simplify the comparison and so reduce the changes to the routines, I will have a couple of Global variables at the top of the module and outside any routine for the row and column indices
Dim Cms() As Variant, Rs() As Variant
This will allow me to refer to, that is to say change and use, in any copy of the recursion routine. (It would also be an alternative place here at the top of the module and outside any routine for our main array, arrTS(): we could then always refer to this, and then not need the ByRef arsRef() at the signature line of the recursion routine. But for now I will leave that as it is for closer comparison of the routines )
To help in the development of this coding and to help with the explanation here, I have also moved the variable for the test range, RngToSort , to the top of the module and outside any routine to make it a global variable: This way I can use it’s dimensions to position intermediate paste outs of the arrTS(). For example , I have added a section immediately after the end of the main outer loop == for sorting, ' Captains Blog, Start Treck , which pastes out the current state of the sorted array , arrTS(), along with the current state of the indices, Rs()

' Captains Blog, Start Treck
Let RngToSort.Offset((RngToSort.Rows.Count * (CopyNo + 1)), 0).Value = arsRef()
RngToSort.Offset((RngToSort.Rows.Count * (CopyNo + 1)), -1).Resize(UBound(Rs(), 1), UBound(Rs(), 2)).Value = Rs()
Debug.Print " Running Copy " & CopyNo & " of routine." & vbCr & vbLf & " Sorted rows " & strRws & " based on values in column " & Clm & vbCr & vbLf & " Checking now for Dups in that last sorted list" & vbCr & vbLf
For color=Blue]Sub[/color] SimpleArraySort7(__ I will also include a new array variable , as a global variable, arrIndx(). This I will fill by the formula line of
arrIndx() = Application.Index(arrIndx(), Rs(), Cms())

Modifying indices values in main sort loop sorting
The way the current coding is organised this is fairly simple. We have sections where row elements are swapped. We use the row information in the variables rOuter and rInner. So quite simply, we do the same swap for row indices,


Initial row indicees

Evaluate(Row(1to15)).JPG : https://imgur.com/UVTQCYO


Evaluate(Column(1to6)).JPG : https://imgur.com/jbaZdgJ

DocAElstein
09-16-2015, 09:23 PM
Simple recursion example 2
In simple general terms a recursion routine can be an efficient way to do a sort of looping while looking for something. Sometimes the idea of “tunnelling down” or digging down” can describe the situation well. Sometimes a standard looping routine of the Do Loop While type form can replace a recursion routine more efficiently ( https://www.excelforum.com/tips-and-tutorials/1213798-all-sub-folder-and-file-list-from-vba-recursion-routine-explanation-and-method-comparison.html )
The characteristic that possibly distinguishes recursion routines is the ability to seemingly intelligently go up and down: Compare it to the situation of digging down , whereby from time to time you come back up a bit, then dig down again in a slightly different direction. That is best illustrated by using a recursion routine for one of its most common practical uses, that of searching through Folders and sub Folders in a Directory. That will be done in the over next post.
As a pre requisite to that we will demonstrate how a much simpler recursion routine may dig down until a condition is met, and then, thereafter it comes back up, level for level , i.e. copy for copy. This usage is very similar to the standard looping routine of the Do Loop While type form except that you have a last coming back up the levels, or coming back up the copies, which you would not have with a simple Do Loop While type form ( https://www.excelforum.com/development-testing-forum/1101544-thread-post-appendix-no-reply-needed-please-do-not-delete-thanks-4.html#post4221234 )

We did not experience this coming back up in the last code because we Stoped. In general use of a recursion process, we do not have a simple way to end with like If ____ Then End Sub. Such a solution would be difficult to implement in a recursion process, as we would be ending the current copy with the End Sub.
So generally a recursion process ends by somehow “coming back up levels” or ending each copy one after the other, either
in sequence for a simple routine,
or
after going back and forth / up and down in a more complicated implementation of a recursion process.

In most cases the coming back up is rarely experienced. We have specifically a message box at that point to show when a copy of the routine is ended. In practical uses what happens at this point is ether nothing, or for more complex implementation of recursion, we may be in a Loop at that point which would determine if we “go back down” again: Some controlled looping at this point is what triggers the possibility to “go back down” , pseudo…

Sub Sub2( CpyNo , ______ )
CurrentCopyNumber=CpyNo


__Do
___Call Sub2(CurrentCopyNumber+1 , ______ )
__Loop While__
MsgBox Prompt:="You are Ending Sub2 , copy " & CurrentCopyNumber
End Sub

This will be discussed in the over next post.
For now we look at the simple case

One immediate way to stop us going further than say the second copy, would be to change our last coding pair from…_

Sub Sub1()
Dim StrtCpyNo As Long ' To count copy number of code instructions being run
Let StrtCpyNo = 1


Call Sub2(CpyNo:=StrtCpyNo, Msg:="Initial Message")

MsgBox Prompt:="Ending main procedure"
End Sub
' Code above is Main calling procedure '_________________________________________________ ___________________

' Code below is called procedure
Sub Sub2(ByVal CpyNo As Long, ByVal Msg As String)
Dim CopyNo As Long ' This is to indicate which copy of Sub2 is currently running
Let CopyNo = CpyNo
MsgBox Prompt:="You are Starting Sub2 , copy " & CopyNo

Call Sub2(CpyNo:=CopyNo + 1, Msg:="Message coming from Sub2, copy " & CopyNo & "")
MsgBox Prompt:="You are Ending Sub2 , copy " & CopyNo
End Sub

_... to

Sub Sub1()
Dim StrtCpyNo As Long ' To count copy number of code instructions being run
Let StrtCpyNo = 1


Call Sub2(CpyNo:=StrtCpyNo, Msg:="Initial Message")

MsgBox Prompt:="Ending main procedure"
End Sub
' Code above is Main calling procedure '_________________________________________________ ____________________________

' Code below is called procedure
Sub Sub2(ByVal CpyNo As Long, ByVal Msg As String)
Dim CopyNo As Long ' This is to indicate which copy of Sub2 is currently running
Let CopyNo = CpyNo
MsgBox Prompt:="You are Starting Sub2 , copy " & CopyNo

If CopyNo < 2 Then Call Sub2(CpyNo:=CopyNo + 1, Msg:="Message coming from Sub2, copy " & CopyNo & "")
MsgBox Prompt:="You are Ending Sub2 , copy " & CopyNo
End Sub

You can safely run the above coding, ( by running Sub1 ) , in normal mode, as it will no longer try to go on for ever. But it is probably more demonstrative to use debug F8 mode


Here is an attempt to show the last run as Excel VBA actually experienced it, - running Sub1 followed by two separate copies of Sub2, or rather
Start Sub1
_Start Sub2Copy1
___Start Sub2Copy2
___End Sub2Copy2
_End Sub2Copy2
End Sub1

Sub Sub1Sub2Sub2()
Dim StrtCpyNo As Long ' To count copy number of code instructions being run
Let StrtCpyNo = 1


'Call Sub2(CpyNo:=StrtCpyNo, Msg:="Initial Message")
' Sub2 Copy 1
Dim CpyNo As Long: Let CpyNo = StrtCpyNo: Dim Msg As String: Let Msg = "Initial Message"
Dim CopyNo As Long ' This is to indicate which copy of Sub2 is currently running
Let CopyNo = CpyNo
MsgBox Prompt:="You are Starting Sub2 , copy " & CopyNo

If CopyNo < 2 Then
'Call Sub2(CpyNo:=CopyNo+1, Msg:="Message coming from Sub2, copy " & CopyNo & "")
' Sub2 Copy 2
Dim CpyNo_ As Long: Let CpyNo_ = CopyNo + 1: Dim Msg_ As String: Let Msg_ = "Message coming from Sub2, copy " & CopyNo & ""
Dim CopyNo_ As Long ' This is to indicate which copy of Sub2 is currently running
Let CopyNo_ = CpyNo_
MsgBox Prompt:="You are Starting Sub2 , copy " & CopyNo_
End If
If CopyNo_ < 2 Then
Else
MsgBox Prompt:="You are Ending Sub2 , copy " & CopyNo_
End If
'End Sub2 ' End Copy 2 of Sub2
MsgBox Prompt:="You are Ending Sub2 , copy " & CopyNo
'End Sub2 ' End Copy 1 of Sub2

MsgBox Prompt:="Ending main procedure"
End Sub

DocAElstein
09-16-2015, 09:23 PM
.... this non-looping macro should also work... I sometimes wonder whether we fool ourselves into thinking that these things are non looping. I don’t think any of us is privy to exactly what Excel is doing behind the scenes when these things work. The lack of clear documentation to these “array” type workings and the little fiddles you have to do sometimes to get these to work, makes me wonder if anyone knows exactly what is going wrong. Here is one of not many theories about how these sort of things might work.. http://www.excelfox.com/forum/showthread.php/2145-Excel-VBA-Interception-and-Implicit-Intersection-and-VLookUp That might suggest that what happens with these Evaluate Range things is similar to how maybe the CSE Array Entry formulas work in spreadsheets:
It suggests that we maybe “tap in” to something that gets done anyway whether we want to or not, and as such we don’t add too much extra. This something could be a “along the row, down a column, along a row…” type thing like a raster across an old telly screen which updates a complete screen/ worksheet. When we define the area in the initial selection of the spreadsheet area before adding our formula in a type 2 CSE Array Entry we may simply be exposing a large area rather than the usual single cell in a complete screen update. In other words the extra information for a multi cell range is there anyway and all we do is open up a bigger window so that we see it at once.
As far as I know, Evaluate was / is something to let you construct a string using both Excel spreadsheet and VBA stuff and then evaluate that string as if you wrote it manually in a spreadsheet cell.
Whether or not it was planned that it could be used in the way that people like Rick do as a sort of hidden type 2 CSE Array Entry formula , or whether that is an accident, I don’t know.

I don’t think I have ever noticed that these things wont work as a type 2 CSE Array Entry , ( occasionally they don’t work in evaluate and we have to coerce them into working ) , so taking Ricks last masterpiece and putting it in a spreadsheet like this will confirm that it works

Dim LastRow As Long, strEval As String
Let LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Let strEval = Replace(Replace("IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A#,"" "",""""),"","","""")),IF(LEFT(A1:A@,4)=""2018"",TRIM(A1:A@&"" ""&A2:A#),""""),IF(LEFT(A1:A@,4)=""2018"",A1:A@,""""))", "#", LastRow + 1), "@", LastRow)
Range("B1:B" & LastRow).FormulaArray = "=" & strEval
Debug.Print strEval 'IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A1," ",""),",","")),IF(LEFT(A1:A0,4)="2018",TRIM(A1:A0&" "&A2:A1),""),IF(LEFT(A1:A0,4)="2018",A1:A0,""))
_____ Workbook: NormanOrrinFilter.xlsm ( Using Excel 2007 32 bit )
Row\Col
B

1


2


3


4


5


6


7


8


9


10


112018, 1, 90515, 10024515, G9, SBlabla (HQ), CHE, BLABLA, blabla, 10012098, 12003.5


122018, 1, 90629, 10022334, P3, BLABLA blabla (blablabla), CHE, BLABLA,blabla, 10033609, 13941.72


132018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah, 10006098, 15392.64


14


152018, 1, 90765, 10012123, P4, Ch of Blabla(Blabla of Blabla), CHE, BLA-BLA,Bla Blabla, 10005678, 16231.7


16


172018, 1, 90712, 10022908, P4, Snr BLA Off (Strat BLa, BLA), CHE, BLABLA,Bla BLabla, 10023234 14900.28


18


192018, 1, 90919, 10020984, P2, Ass BLA Balbla, CHE, BLA,Blabla, 10033098, 10486.33


202018, 1, 95706, 10023098, NB, Assc BLA Blabal (LatBLAa), BLA, BLABLABLA,Blabla, 10034318, 7566.31


21


22


23


24


25


26


27


28


292018, 1, 95716, 10018763, NA, Asst BLA Off (Blabla & Multi-BLa), BLA, BLA,Bla, 10097776, 8607.96


302018, 1, 99716, 10026132, G5, Snr BLA Asst (Bla Blabla), BLA, BLABLA,bla BLa, 18767043, 5477.44


312018, 1, 99716, 10016545, G6, Blabla Blabla (BLA), BLA, BLABLABLA,Blabla, 1097029, 5325.3


32


33
Worksheet: Rick
_.________________________________--

I would guess that whoever wrote the .SpecialCells did that quite efficiently. Who knows, they may even have used some of this “hidden array “ techniques to do it.
So a combination of .SpecialCells and evaluate range one liners sounds an attractive combination , in my opinion.

_._________
Coming back to the solution from Rick… I was interested to work through it.. so I did. I put my workings here, as the OP or anyone else viewing this thread might be interested.

Alan

DocAElstein
09-17-2015, 02:31 AM
Post to support this Thread:
http://www.excelfox.com/forum/showthread.php/2293-Move-values-in-rows-at-the-end-of-the-preceding-row?p=10888#post10888
_1) This part of Rick’s solution
Evaluate(Replace(Replace("IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A#,"" "",""""),"","","""")),IF(LEFT(A1:A@,4)=""2018"",TRIM(A1:A@&"" ""&A2:A#),""""),IF(LEFT(A1:A@,4)=""2018"",A1:A@,""""))", "#", LastRow + 1), "@", LastRow))

I have seen something similar to this before, but it is lost to mankind hidden down in the comment section of a Blog site, Allen Wyatt’s I think…… so its nice that something like this has seen the light of day here…
If I am not mistaken, this non-looping macro should also work...



Sub ThisShouldWork()
Dim LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:A" & LastRow) = Evaluate(Replace(Replace("IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A#,"" "",""""),"","","""")),IF(LEFT(A1:A@,4)=""2018"",TRIM(A1:A@&"" ""&A2:A#),""""),IF(LEFT(A1:A@,4)=""2018"",A1:A@,""""))", "#", LastRow + 1), "@", LastRow))
Range("A1:A" & LastRow).SpecialCells(xlBlanks).EntireRow.Delete
End Sub



To help simplify the explanation, lets take it that we know our range , ( http://www.excelfox.com/forum/showthread.php/2293-Move-values-in-rows-at-the-end-of-the-preceding-row#post10870 ) so we have LastRow = 40
Two arbitrarily chosen characters, @ and # , are being used to enter into the main formula the LastRow or LastRow +1
Pseudo like we are doing this sort of thing
Replace( “A#” , “#” , “40” ) in order to end up with like “A40”
By inspection of the main formula, and with a bit of eye straining you can probably see where you replace those @ and # with 40 and 41
Just to be sure , running this will get you a nice copy able version of the main formula in the immediate window , ( after running you Hit Ctrl+g from the VB Editor to get the immediate window up):

Sub ThisShouldWork()
Dim LastRow As Long, strEval As String
Let LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Let strEval = Replace(Replace("IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A#,"" "",""""),"","","""")),IF(LEFT(A1:A@,4)=""2018"",TRIM(A1:A@&"" ""&A2:A#),""""),IF(LEFT(A1:A@,4)=""2018"",A1:A@,""""))", "#", LastRow + 1), "@", LastRow)
'Range("B1:B" & LastRow).FormulaArray = "=" & strEval
Debug.Print strEval 'IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A41," ",""),",","")),IF(LEFT(A1:A40,4)="2018",TRIM(A1:A40&" "&A2:A41),""),IF(LEFT(A1:A40,4)="2018",A1:A40,""))

That did work.JPG : https://imgur.com/01sQ91X

_._______________________-
Before moving on a useful note: It is always useful when developing these formulas to view the string in the Immediate window: That can help with tricky syntaxes : The formula seen on the Immediate window must look like a formula in the same syntax as you would manually type it into a cell. So you can see immediately if you get something wrong , such as an error in the finally seen quotes.
_.__________________________
So we have our final formula:
IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A41," ",""),",","")),IF(LEFT(A1:A40,4)="2018",TRIM(A1:A40&" "&A2:A41),""),IF(LEFT(A1:A40,4)="2018",A1:A40,""))
The way these formulas appear to work within the Evaluate(“ “) appears to be tapping into an along the columns , down a row, then along the columns… type updating raster to update a worksheet. The available output then seems to be that which encompasses the deepest and widest ranges. It is a ,little bit more complicated than that ( http://www.excelfox.com/forum/showthread.php/2145-Excel-VBA-Interception-and-Implicit-Intersection-and-VLookUp ) , but for our formula we have nice regular equally sized ranges so we are expecting an output of 1 “wide” and 40 “deep”. So for analysis purposes, we can reduce the formula to 40 similar ones.

Lets take the example of the formula for the 13th “down” output ..
IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")),IF(LEFT(A13,4)="2018",TRIM(A13&" "&A14),""),IF(LEFT(A13,4)="2018",A13,""))
Clearly we need to look at this data to see what that formula will do, because this data is used in that formula
_____ Workbook: NormanOrrinRickFilter.xlsm ( Using Excel 2007 32 bit )
Row\Col
A

132018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah,


1410006098, 15392.64
Worksheet: Rick

We have some nested IFs , and I find it is always a good idea to break those down so that we can start doing them as Excel or VBA would do them, that is to say from the middle working outwards. I tend to do this in a text editor with a horizontal scroll bar, or in the VB Editor window
Formula in VB Editor as comment.JPG : https://imgur.com/3cjyqSR

So this is what we have, broken down into the constituent IF sections.
( It may be better to copy this and view in your VB Editor in a wide window. I am working from the bottom , upwards )

' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), IF(LEFT(A13,4)="2018" , TRIM(A13" "&A14) , "") , IF( LEFT(A13,4)="2018" , A13 ,"" ) )
' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")),IF(LEFT(A13,4)="2018",TRIM(A13" "&A14),"") , IF(LEFT(A13,4)="2018",A13,"") )
' IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")),IF(LEFT(A13,4)="2018",TRIM(A13" "&A14),""),IF(LEFT(A13,4)="2018",A13,""))

Examining the first line , I can evaluate the two innermost IFs and reduce the formula to

' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), TRIM(A13" "&A14) , A13 )
' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), IF(LEFT(A13,4)="2018" , TRIM(A13" "&A14) , "") , IF( LEFT(A13,4)="2018" , A13 ,"" ) )


I will now evaluate some of those SUBSTITUTEs
( Excel Substitute, seems to work similarly to VBA Replace )

' IF( ISNUMBER(0+1000609815392.64), TRIM(A13" "&A14) , A13 )
' IF( ISNUMBER(0+SUBSTITUTE(10006098,15392.64),",","")), TRIM(A13" "&A14) , A13 )

( I am guessing that 0+ will ensure that a number will not be mistaken as a text )

For the case of the 13th “down” formula the final steps in the evaluation go as follows

' 2018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah, 10006098, 15392.64
' TRIM(A13" "&A14)

' IF( True , TRIM(A13" "&A14) , A13 )

Here are all the steps together again

' 2018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah, 10006098, 15392.64
' TRIM(A13" "&A14)

' IF( True , TRIM(A13" "&A14) , A13 )


' IF( ISNUMBER(0+1000609815392.64), TRIM(A13" "&A14) , A13 )
' IF( ISNUMBER(0+SUBSTITUTE(10006098,15392.64),",","")), TRIM(A13" "&A14) , A13 )

' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), TRIM(A13" "&A14) , A13 )
' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), IF(LEFT(A13,4)="2018" , TRIM(A13" "&A14) , "") , IF( LEFT(A13,4)="2018" , A13 ,"" ) )


' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), IF(LEFT(A13,4)="2018" , TRIM(A13" "&A14) , "") , IF( LEFT(A13,4)="2018" , A13 ,"" ) )
' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")),IF(LEFT(A13,4)="2018",TRIM(A13" "&A14),"") , IF(LEFT(A13,4)="2018",A13,"") )
' IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")),IF(LEFT(A13,4)="2018",TRIM(A13" "&A14),""),IF(LEFT(A13,4)="2018",A13,""))


The final result will appear in the 13th down position of the 40 “deep” array final results for the entire formula evaluation.
If you can view that last summary on a wide window, it should be able to see how the differing results for the other 39 results are achieved from the formula
Just to make clear once again what seems to go on in these sort of Evaluate formulas, in the next post is a table showing the actual Evaluateions done by VBA

_._____

_2 The final part of Rick’s solution is
Range("A1:A" & LastRow).SpecialCells(xlBlanks).EntireRow.Delete
This uses the VBA SpecialCells Method to get at the cells with nothing in them. Those are then deleted
Explanation:
VBA SpecialCells Method ( https://www.mrexcel.com/forum/excel-questions/21342-xlcelltypesameformatconditions.html , https://docs.microsoft.com/en-us/office/vba/api/excel.range.specialcells ) returns you a range object ( that range object must not be contiguous ( connected ) cells ) consisting of those cells meeting a specific characteristic. We can choose from a number of characteristics. Here we choose xlBlanks , which refers to the characteristic of the cell being empty. So, if we applied that .SpecialCells(xlBlanks) to this range:.._
Row\Col
B

9


10


112018, 1, 90515, 10024515, G9, SBlabla (HQ), CHE, BLABLA, blabla, 10012098, 12003.5


122018, 1, 90629, 10022334, P3, BLABLA blabla (blablabla), CHE, BLABLA,blabla, 10033609, 13941.72


132018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah, 10006098, 15392.64


14


152018, 1, 90765, 10012123, P4, Ch of Blabla(Blabla of Blabla), CHE, BLA-BLA,Bla Blabla, 10005678, 16231.7

_ … then the returned range from that would be Range(“B9:B10,B14”).
If we then apply .Delete to that range then those cells are removed. If you remove a cell via .Delete then initially there is a real hole, like a “black hole” that can’t really exist in a spreadsheet. So Excel might explode or implode, or you would be sucked into that hole , never to return!!! To prevent that happening, Excel shifts all cells to close that hole, ( and adds a new virgin cell at the bottom or right side to fill the indent there caused by the shift. The default Delete option for the direction of that shift is in our case upwards. Hence after applying the .Delete after applying .SpecialCells(xlBlanks) to the above range, we will be left with
Row\Col
B

92018, 1, 90515, 10024515, G9, SBlabla (HQ), CHE, BLABLA, blabla, 10012098, 12003.5


102018, 1, 90629, 10022334, P3, BLABLA blabla (blablabla), CHE, BLABLA,blabla, 10033609, 13941.72


112018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah, 10006098, 15392.64


122018, 1, 90765, 10012123, P4, Ch of Blabla(Blabla of Blabla), CHE, BLA-BLA,Bla Blabla, 10005678, 16231.7


13


14

What has happened there is the following: Those empty cells ( which were yellow ) have been removed. Other cells have been shifted up to fill up the “holes” created by the removal

_.______________________________________________

Just to make clear once again what seems to go on in these sort of Evaluate formulas, in the next post is a table showing the actual Evaluateions done by VBA

DocAElstein
08-29-2016, 04:12 AM
Continued from last post

In a range evaluate type code line like the one we are considering, Excel VBA seems to do the following ( simplified )

Excel will have an output “window” ( this could be considered as an output table or output array ). The dimensions of this will be that rectangle that allows all used ranges in the formula to be fitted in,
There are some complicated ways in which Excel handles the situation of ranges of varying size, ( http://www.excelfox.com/forum/showthread.php/2145-Excel-VBA-Interception-and-Implicit-Intersection-and-VLookUp ) but for a simpler case of all ranges having the same size, ( in terms of “width” and “depth” ) , as we have, Excel VBA will “expand” its “output window” to this sort of thing:


















































































Excel VBA will do its normal “along the columns, down a row, along the columns…” type thing, in any “Evaluation run”. In our case this will mean that it does an evaluation at each row, going down the rows. This is what Excel VBA does in order to fill that last window of cells, ( I am just showing the first 7 of 40 similar formulas as the full list is to big to fit in a forum post )

=IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2," ",""),",","")),IF(LEFT(A1,4)="2018",TRIM(A1&" "&A2),""),IF(LEFT(A1,4)="2018",A1,""))

=IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A3," ",""),",","")),IF(LEFT(A2,4)="2018",TRIM(A2&" "&A3),""),IF(LEFT(A2,4)="2018",A2,""))

=IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A4," ",""),",","")),IF(LEFT(A3,4)="2018",TRIM(A3&" "&A4),""),IF(LEFT(A3,4)="2018",A3,""))

=IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A5," ",""),",","")),IF(LEFT(A4,4)="2018",TRIM(A4&" "&A5),""),IF(LEFT(A4,4)="2018",A4,""))

=IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A6," ",""),",","")),IF(LEFT(A5,4)="2018",TRIM(A5&" "&A6),""),IF(LEFT(A5,4)="2018",A5,""))

=IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A7," ",""),",","")),IF(LEFT(A6,4)="2018",TRIM(A6&" "&A7),""),IF(LEFT(A6,4)="2018",A6,""))

=IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A8," ",""),",","")),IF(LEFT(A7,4)="2018",TRIM(A7&" "&A8),""),IF(LEFT(A7,4)="2018",A7,""))


Excel VBA will effectively make 40 formulas and place in the “output window” the result of the evaluation of those formulas
The full demo code in the next post includes a code line to put in all 40 formulas in an arbitrary 40 “deep” x 1 “wide” range ("J5:J44")

DocAElstein
01-25-2017, 10:11 PM
Full demo code to accompany last post:


Option Explicit
Sub ThisShouldWork()
Dim LastRow As Long, strEval As String
Let LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Let strEval = Replace(Replace("IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A#,"" "",""""),"","","""")),IF(LEFT(A1:A@,4)=""2018"",TRIM(A1:A@&"" ""&A2:A#),""""),IF(LEFT(A1:A@,4)=""2018"",A1:A@,""""))", "#", LastRow + 1), "@", LastRow)
Debug.Print strEval ' Hit Ctrl+g from the VB Editor to get the Immediate window up. 'IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A41," ",""),",","")),IF(LEFT(A1:A40,4)="2018",TRIM(A1:A40&" "&A2:A41),""),IF(LEFT(A1:A40,4)="2018",A1:A40,""))
'This is the spreadsheet equivalent to Rick's Evaluate
Range("B1:B" & LastRow).FormulaArray = "=" & strEval
'This gives a demo of the actual formulas that Excel VBA does
Range("J5:J44").Value = "=IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2,"" "",""""),"","","""")),IF(LEFT(A1,4)=""2018"",TRIM(A1&"" ""&A2),""""),IF(LEFT(A1,4)=""2018"",A1,""""))" ' Applying the fixed vector notation (Excel instructed to do that by no $s) will result in the same relative formula. Displayed will be the actual formula ( in the relative form, but that is not important)

' Final solution Rick : http://www.excelfox.com/forum/showthread.php/2293-Move-values-in-rows-at-the-end-of-the-preceding-row?p=10888#post10888
Range("A1:A" & LastRow) = Evaluate(Replace(Replace("IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A2:A#,"" "",""""),"","","""")),IF(LEFT(A1:A@,4)=""2018"",TRIM(A1:A@&"" ""&A2:A#),""""),IF(LEFT(A1:A@,4)=""2018"",A1:A@,""""))", "#", LastRow + 1), "@", LastRow))
' Range("A1:A" & LastRow).SpecialCells(xlBlanks).EntireRow.Delete ' This will mess up now due to my .FormulaArray as you can't delete bits of that
End Sub



' 2018, 1, 90709, 10020009, P4, Blabla og Blalala (NY), CHE, Blabla,Bla-ah, 10006098, 15392.64
' TRIM(A13" "&A14)

' IF( True , TRIM(A13" "&A14) , A13 )


' IF( ISNUMBER(0+1000609815392.64), TRIM(A13" "&A14) , A13 )
' IF( ISNUMBER(0+SUBSTITUTE(10006098,15392.64),",","")), TRIM(A13" "&A14) , A13 )

' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), TRIM(A13" "&A14) , A13 ) )
' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), IF(LEFT(A13,4)="2018" , TRIM(A13" "&A14) , "") , IF( LEFT(A13,4)="2018" , A13 ,"" ) )


' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")), IF(LEFT(A13,4)="2018" , TRIM(A13" "&A14) , "") , IF( LEFT(A13,4)="2018" , A13 ,"" ) )
' IF( ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")),IF(LEFT(A13,4)="2018",TRIM(A13" "&A14),"") , IF(LEFT(A13,4)="2018",A13,"") )
' IF(ISNUMBER(0+SUBSTITUTE(SUBSTITUTE(A14," ",""),",","")),IF(LEFT(A13,4)="2018",TRIM(A13" "&A14),""),IF(LEFT(A13,4)="2018",A13,""))

DocAElstein
02-05-2017, 06:44 PM
( P.M. )

Hi Sam,
I have quick question. I am asking if I may post codes , Tables, etc. in , for example your Test Area, and reference those Posts from other Forums.

_.....The idea is basically similar to something I do already:...You may have noticed:..._..

I current use this thread in your Test Area Sub Forum.
http://www.excelfox.com/forum/showthread.php/2056-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)
I reference codes or table or extended explanations there from other posts.
I do this so as to have less clutter in the main Threads from which these “appendix” posts are referenced.

I also do this over at ExcelForum, where these “appendix” Threads appear very popular
http://www.excelforum.com/showthread.php?t=1101544
http://www.excelforum.com/showthread.php?t=1148621
http://www.excelforum.com/showthread.php?t=1147913
http://www.excelforum.com/showthread.php?t=1154829
Those are mainly used by me for “appendix” posts referenced by one or more reply posts I do when answering Threads at ExcelForum.
Occasionally, I also reference those posts from other Forums.

There is a disadvantage for me in using those Threads at ExcelForum.
_ You must be logged in to view the Test Area at ExcelForum, so people who are not registered cannot vie them.
_ You cannot use HTML anywhere at ExcelForum ( you have that enabled in your Test Sub Forum )
_ ExcelForum is increasingly unavailable for long periods due to Software problems
_ Many other software problems at ExcelForum , including viruses, are making people more and more reluctant to use the site.

So, if I may, I would like to use in addition ( or possibly instead ) ExcelFox for some of my “appendix” Posts
_......

So, if may, I would like to post codes and the such that may not ( at least initially ) be relevant to Threads at ExcelFox. I will then post a link to those posts as appropriate in other Forums.
I do not think it is appropriate for me necessarily to post in these in the Excel Tips and Tricks Sub Forum as the content may not be “stand alone”, that is too say the content may not be so meaningful on its own.
( I am only a part time “Exceller”, and a Novice at that – so I would never get anywhere near the Heights of the likes of Rick Rothstein oder Rajan Verma. – So there would never be the requirement for me to have my own “corner” )
_.......

( By the way, I do this partly already: In my signature both at ExcelFox and ExcelForum
http://www.excelfox.com/forum/showthread.php/2079-test-BB-Code?p=9821#post9821
I assumed that was OK as I am just referencing some Forum Posting Tools that I use in both Forums )



Thanks
Alan Elston.






Hi Admin,
Thanks for the reply
As I mentioned, I did not want an individual Forum. Indeed even if available, I would not think it appropriate for my posts.
I was just wondering if I could post some of my stuff in the Test Area, for the reasons I mentioned:
_ Posts that are not “stand alone” Tips and tricks are less suited to Tips, Tricks. They would be for me to reference to when answering specific Posts and Blogs elsewhere.
_ In Test Forum I have HTML
_ In Test forum I have unlimited Edit time.


So the question was if, in addition to Tips and Tutorials, I may also post in the Test Area, in the fashion that I do, as indicated, at ExcelForum?
http://www.excelforum.com/development-testing-forum/1101544-thread-post-appendix-no-reply-needed-please-do-not-delete-thanks.html
http://www.excelforum.com/development-testing-forum/1086445-forum-tools-test-no-reply-needed.html
http://www.excelforum.com/development-testing-forum/1154829-collection-stuff-of-codes-for-other-threads-no-reply-needed.html


_ The purpose of this will be following:
Codes and Information , To be referenced in this web site , Also to be referenced from other web sites
Thanks
Alan

No issues :)

( Per PM: )

No restriction in Test Area :)

Admin
02-06-2017, 01:33 PM
Hi Alan,

Why don't you post the codes in the original thread ? Or are you testing the code over here ?

https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg.9zaUSUoUUYs9zciSZa95 9d (https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg.9zaUSUoUUYs9zciSZa95 9d)
https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg.9zaUSUoUUYs9zckCo1tv PO (https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg.9zaUSUoUUYs9zckCo1tv PO)
https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgwMsgdKKlhr2YPpxXl4AaABAg (https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgwMsgdKKlhr2YPpxXl4AaABAg)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwTUdEgR4bdt6crKXF4AaABAg.9xmkXGSciKJ9xonTti2s Ix (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwTUdEgR4bdt6crKXF4AaABAg.9xmkXGSciKJ9xonTti2s Ix)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwWw16qBFX39JCRRm54AaABAg.9xnskBhPnmb9xoq3mGxu _b (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwWw16qBFX39JCRRm54AaABAg.9xnskBhPnmb9xoq3mGxu _b)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9xon1p2ImxO (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9xon1p2ImxO)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgybZfNJd3l4FokX3cV4AaABAg.9xm_ufqOILb9xooIlv5P LY (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgybZfNJd3l4FokX3cV4AaABAg.9xm_ufqOILb9xooIlv5P LY)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9y38bzbSqaG (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9y38bzbSqaG)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgyWm8nL7syjhiHtpBF4AaABAg.9xmt8i0IsEr9y3FT9Y9F eM (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgyWm8nL7syjhiHtpBF4AaABAg.9xmt8i0IsEr9y3FT9Y9F eM)
https://www.youtube.com/watch?v=bRd4mJglWiM&lc=UgxRmh2gFhpmHNnPemR4AaABAg.A0opm95t2XEA0q3Kshmu uY (https://www.youtube.com/watch?v=bRd4mJglWiM&lc=UgxRmh2gFhpmHNnPemR4AaABAg.A0opm95t2XEA0q3Kshmu uY)
https://www.youtube.com/watch?v=bRd4mJglWiM&lc=UgxRmh2gFhpmHNnPemR4AaABAg (https://www.youtube.com/watch?v=bRd4mJglWiM&lc=UgxRmh2gFhpmHNnPemR4AaABAg)
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=314837#p314837 (https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=314837#p314837)
https://www.eileenslounge.com/viewtopic.php?f=21&t=40701&p=314836#p314836 (https://www.eileenslounge.com/viewtopic.php?f=21&t=40701&p=314836#p314836)
https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314621#p314621 (https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314621#p314621)
https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314619#p314619 (https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314619#p314619)
https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314600#p314600 (https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314600#p314600)
https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314599#p314599 (https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314599#p314599)
https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314274#p314274 (https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314274#p314274)
https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314229#p314229 (https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314229#p314229)
https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314195#p314195 (https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314195#p314195)
https://www.eileenslounge.com/viewtopic.php?f=36&t=39706&p=314110#p314110 (https://www.eileenslounge.com/viewtopic.php?f=36&t=39706&p=314110#p314110)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

DocAElstein
02-06-2017, 02:18 PM
Hi Admin
Yes, just testing it here.
I often edit and re use the post.
I sometimes re use, edit a bit etc.
So just testing in this Thread.
Another Thread I use here for the codes I use in answering Threads. That helps to keep the Thread less clutered for longer codes.
I post most in the original Threads.
Alan

https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://eileenslounge.com/viewtopic.php?p=318868#p318868 (https://eileenslounge.com/viewtopic.php?p=318868#p318868)
https://eileenslounge.com/viewtopic.php?p=318311#p318311 (https://eileenslounge.com/viewtopic.php?p=318311#p318311)
https://eileenslounge.com/viewtopic.php?p=318302#p318302 (https://eileenslounge.com/viewtopic.php?p=318302#p318302)
https://eileenslounge.com/viewtopic.php?p=317704#p317704 (https://eileenslounge.com/viewtopic.php?p=317704#p317704)
https://eileenslounge.com/viewtopic.php?p=317704#p317704 (https://eileenslounge.com/viewtopic.php?p=317704#p317704)
https://eileenslounge.com/viewtopic.php?p=317857#p317857 (https://eileenslounge.com/viewtopic.php?p=317857#p317857)
https://eileenslounge.com/viewtopic.php?p=317541#p317541 (https://eileenslounge.com/viewtopic.php?p=317541#p317541)
https://eileenslounge.com/viewtopic.php?p=317520#p317520 (https://eileenslounge.com/viewtopic.php?p=317520#p317520)
https://eileenslounge.com/viewtopic.php?p=317510#p317510 (https://eileenslounge.com/viewtopic.php?p=317510#p317510)
https://eileenslounge.com/viewtopic.php?p=317547#p317547 (https://eileenslounge.com/viewtopic.php?p=317547#p317547)
https://eileenslounge.com/viewtopic.php?p=317573#p317573 (https://eileenslounge.com/viewtopic.php?p=317573#p317573)
https://eileenslounge.com/viewtopic.php?p=317574#p317574 (https://eileenslounge.com/viewtopic.php?p=317574#p317574)
https://eileenslounge.com/viewtopic.php?p=317582#p317582 (https://eileenslounge.com/viewtopic.php?p=317582#p317582)
https://eileenslounge.com/viewtopic.php?p=317583#p317583 (https://eileenslounge.com/viewtopic.php?p=317583#p317583)
https://eileenslounge.com/viewtopic.php?p=317605#p317605 (https://eileenslounge.com/viewtopic.php?p=317605#p317605)
https://eileenslounge.com/viewtopic.php?p=316935#p316935 (https://eileenslounge.com/viewtopic.php?p=316935#p316935)
https://eileenslounge.com/viewtopic.php?p=317030#p317030 (https://eileenslounge.com/viewtopic.php?p=317030#p317030)
https://eileenslounge.com/viewtopic.php?p=317030#p317030 (https://eileenslounge.com/viewtopic.php?p=317030#p317030)
https://eileenslounge.com/viewtopic.php?p=317014#p317014 (https://eileenslounge.com/viewtopic.php?p=317014#p317014)
https://eileenslounge.com/viewtopic.php?p=316940#p316940 (https://eileenslounge.com/viewtopic.php?p=316940#p316940)
https://eileenslounge.com/viewtopic.php?p=316927#p316927 (https://eileenslounge.com/viewtopic.php?p=316927#p316927)
https://eileenslounge.com/viewtopic.php?p=316875#p316875 (https://eileenslounge.com/viewtopic.php?p=316875#p316875)
https://eileenslounge.com/viewtopic.php?p=316704#p316704 (https://eileenslounge.com/viewtopic.php?p=316704#p316704)
https://eileenslounge.com/viewtopic.php?p=316412#p316412 (https://eileenslounge.com/viewtopic.php?p=316412#p316412)
https://eileenslounge.com/viewtopic.php?p=316412#p316412 (https://eileenslounge.com/viewtopic.php?p=316412#p316412)
https://eileenslounge.com/viewtopic.php?p=316254#p316254 (https://eileenslounge.com/viewtopic.php?p=316254#p316254)
https://eileenslounge.com/viewtopic.php?p=316046#p316046 (https://eileenslounge.com/viewtopic.php?p=316046#p316046)
https://eileenslounge.com/viewtopic.php?p=317050&sid=d7e077e50e904a138c794e1f2115da95#p317050 (https://eileenslounge.com/viewtopic.php?p=317050&sid=d7e077e50e904a138c794e1f2115da95#p317050)
https://www.youtube.com/@alanelston2330 (https://www.youtube.com/@alanelston2330)
https://www.youtube.com/watch?v=yXaYszT11CA&lc=UgxEjo0Di9-9cnl8UnZ4AaABAg.9XYLEH1OwDIA35HNIei0z- (https://www.youtube.com/watch?v=yXaYszT11CA&lc=UgxEjo0Di9-9cnl8UnZ4AaABAg.9XYLEH1OwDIA35HNIei0z-)
https://eileenslounge.com/viewtopic.php?p=316154#p316154 (https://eileenslounge.com/viewtopic.php?p=316154#p316154)
https://www.youtube.com/watch?v=TW3l7PkSPD4&lc=UgwAL_Jrv7yg7WWC8x14AaABAg (https://www.youtube.com/watch?v=TW3l7PkSPD4&lc=UgwAL_Jrv7yg7WWC8x14AaABAg)
https://teylyn.com/2017/03/21/dollarsigns/#comment-191 (https://teylyn.com/2017/03/21/dollarsigns/#comment-191)
https://eileenslounge.com/viewtopic.php?p=317050#p317050 (https://eileenslounge.com/viewtopic.php?p=317050#p317050)
https://eileenslounge.com/viewtopic.php?f=27&t=40953&p=316854#p316854 (https://eileenslounge.com/viewtopic.php?f=27&t=40953&p=316854#p316854)
https://www.eileenslounge.com/viewtopic.php?v=27&t=40953&p=316875#p316875 (https://www.eileenslounge.com/viewtopic.php?v=27&t=40953&p=316875#p316875)
https://eileenslounge.com/viewtopic.php?p=316057#p316057 (https://eileenslounge.com/viewtopic.php?p=316057#p316057)
https://eileenslounge.com/viewtopic.php?p=315915#p315915 (https://eileenslounge.com/viewtopic.php?p=315915#p315915)
https://eileenslounge.com/viewtopic.php?p=316705#p316705 (https://eileenslounge.com/viewtopic.php?p=316705#p316705)
https://eileenslounge.com/viewtopic.php?p=316704#p316704 (https://eileenslounge.com/viewtopic.php?p=316704#p316704)
https://eileenslounge.com/viewtopic.php?p=176255#p176255 (https://eileenslounge.com/viewtopic.php?p=176255#p176255)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

Admin
02-06-2017, 04:03 PM
Hi Admin
Yes, just testing it here.
I often edit and re use the post.
I sometimes re use, edit a bit etc.
So just testing in this Thread.
Another Thread I use here for the codes I use in answering Threads. That helps to keep the Thread less clutered for longer codes.
I post most in the original Threads.
Alan

No issues :)

DocAElstein
02-13-2018, 12:30 PM
Inserting code lines
The line number of the code to which 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. In other words , VBA holds somewhere in memory a set of numbers like pseudo the 1 2 3 and 4 here:
1 Option Explicit
2 Sub MyCode()
3 ‘Code
4 End Sub
These numbers we do not see and they are independent of any code lines which we may add: ( We can in addition , use any line numbers or labels as we choose. ( We can choose to use the same line numbers as those held internally, which I do in some places below, just to aid in the demonstration. Therefore those numbers which I use can be regarded , for demonstration purposes, as those held internally ) )

Single lines
Important to note here is that a virgin code module has no code lines. It cannot be thought of in terms of a spreadsheet of rows waiting to be filed in. You cannot reference any row in the code module until either
_ typed lines are present
or
_ at least the rows “exist” as for example , by hitting the Enter key.
However, if you try to insert lines/ rows above the current maximum row, using coding, then the coding will not error: it will add a new line at one line above the last used line.
If you insert lines/rows at up to and including the last used row, then all existing lines get shifted down
Because of these facts, it is easy to get disorientated in coding that inserts lines.
Here an example: we insert lines at arbitrary non existent line numbers well above the last line, here the code before and after running the code:
Before:

' Line 1 Note: I add these numbers just for demonstration to represent the numbers held internally by VBA for referring to lines by number in a code module: We may use any numbers in any order. But they have nothing to do with the internally held numbers. I choose to use the same value as the internally held corresponding numbers for the line here just for demonstration purposes
Sub Insuerts() ' Line 2
3 Dim CodMod As Object: Set CodMod = ThisWorkbook.VBProject.VBComponents.VBE.ActiveCode Pane.CodeModule
4 CodMod.insertlines Line:=2000, String:="' Line 9"
5 CodMod.insertlines Line:=15, String:="' Line 10"
6 CodMod.insertlines Line:=159, String:="' Line " & CodMod.countoflines + 1 ' CodMod.countoflines evaluates to 10 after lines 9 and 10 were added in the last two lines , and then this line is added at the end so becomes line 11
End Sub ' Line 7
' line 8 This is the last line used Before the code is run
After:

' Line 1
Sub Insuerts()
3 Dim CodMod As Object: Set CodMod = ThisWorkbook.VBProject.VBComponents.VBE.ActiveCode Pane.CodeModule
4 CodMod.insertlines Line:=2000, String:="' Line 9"
5 CodMod.insertlines Line:=15, String:="' Line 10"
6 CodMod.insertlines Line:=159, String:="' Line " & CodMod.countoflines + 1 ' CodMod.countoflines evaluates to 10 after lines 9 and 10 were added in the last two lines , and then this line is added at the end so becomes line 11
End Sub
' line 8
' Line 9
' Line 10
' Line 11
The above shows us that “inserting” above the last existing code line will actually add a single code line at the next line/row above the last existing line. Looping to add lines at the end of a code module is therefore somewhat redundant as a code line such as the following would ensure that lines are added sequentially
__.insertlines Line:=__ .countoflines + 1, String:=" ' This will be at the next free line. "
In that code line, any number >=1 can be used in place of 1
Care must be taken when “adding” code lines using insertlines . For example if the first insertlines from the last ( After ) , code is modified to insert/add at the last line such:…_
' Line 1
Sub Insuerts()
3 Dim CodMod As Object: Set CodMod = ThisWorkbook.VBProject.VBComponents.VBE.ActiveCode Pane.CodeModule
4 CodMod.insertlines Line:=CodMod.countoflines, String:="' New Line" ' this will insert at line 11 – currently CodMod.countoflines=11
'5 CodMod.insertlines Line:=15, String:="' Line 10"
'6 CodMod.insertlines Line:=159, String:="' Line " & CodMod.countoflines + 1 11
End Sub
' line 8
' Line 9
' Line 10
' Line 11 _.....then the results after running that above code will be as follows…._
' Line 1
Sub Insuerts()
3 Dim CodMod As Object: Set CodMod = ThisWorkbook.VBProject.VBComponents.VBE.ActiveCode Pane.CodeModule
4 CodMod.insertlines Line:=CodMod.countoflines, String:="' New Line"
'5 CodMod.insertlines Line:=15, String:="' Line 10"
'6 CodMod.insertlines Line:=159, String:="' Line " & CodMod.countoflines + 1 ' CodMod.countoflines evaluates to 10 , and then this line is added at the end so beacomes line 11
End Sub
' line 8
' Line 9
' Line 10
' New Line
' Line 11_.... as we see the code at ( and above if there had been ) the insert line is shifted down. In this case we inserted at the last line, rather than, as previously , trying to insert above the last line

Multi line inserting. In one go. Single string
Like many seemingly “page” type things in computers, the “page text” is actually held in a single long string. By analysing the string in detail , ( SLLHkjsjhfkJHFhfsajkhfaskjfhakjfhkjfhkjfhskjfhs ) , we often find that we have a “character” or characters of this form : vbCr & vbLf . This is a throw back to old computer printer things and this forces a carriage return and line feed. In other word it “makes a new line. We find that these constants are in the string held for a spreadsheet multi line range as well as that for the text in a code module. It can therefore be convenient to use a string of that form in a single string insert line to copy a multi line range into a code module. http://www.eileenslounge.com/viewtopic.php?f=30&t=31395#p242941

For this Thread we will insert/add single lines at a time, to allow some formatting of each line.


Multi line inserting. Via looping.
If lines are inserted in a loop, then things occur in a simple way, (We are considering here that each loop inserts one line ): a line is inserted exactly as indicated in the argument line:=. All existing lines are shifted upwards. So finally all lines above the code section inserted by the looping will be at a line number equall to its original number + the number of loops done.
Inserting, or rather adding, lines beyond the current last line is a bit more subtle to understand.
As noted previously, we can’t actually directly add a line or insert above the last existing line. If we try to add/insert above the last line then a new line is added. This means that the actual line number given will be ignored, and the added code section will be directly above the previous coding. However, if we want our given line number to “pseudo” define the line number finally of the added lines, then we can do that if we give the start line number that of one more than the current last line number.
Here a demo example
Before:
'line 1 Note: I add these numbers just for demonstration to represent the numbers held internally by VBA for referring to lines by number in a code module: We may use any numbers in any order. But they have nothing to do with the internally held numbers. I choose to use the same value as the internally held corresponding numbers for the line here just for demonstration purposes
'Line 2
Sub LoopYinLinesTiddlyHiFoo()
4 Dim VBIDEVBAProj As Object
5 Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.codemodu le
6 Dim LineNo As Long, StartLine As Long, StopLine As Long
7 Let StartLine = VBIDEVBAProj.countoflines + 1: Let StopLine = StartLine + 4
8 For LineNo = StartLine To StopLine
9 VBIDEVBAProj.insertlines Line:=LineNo, String:="'Line " & LineNo
10 Next LineNo
End Sub
After:
'line 1
'Line 2
Sub LoopYinLinesTiddlyHiFoo()
4 Dim VBIDEVBAProj As Object
5 Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.codemodu le
6 Dim LineNo As Long, StartLine As Long, StopLine As Long
7 Let StartLine = VBIDEVBAProj.countoflines + 1: Let StopLine = StartLine + 4
8 For LineNo = StartLine To StopLine
9 VBIDEVBAProj.insertlines Line:=LineNo, String:="'Line " & LineNo
10 Next LineNo
End Sub
'Line 12
'Line 13
'Line 14
'Line 15
'Line 16

The important point to note here is that we have not defined where the lines go directly in terms of the .insertlines Line:= given. We have simply adjusted the numbers used in the loop so that it appears that way.
Just to help make that point clear. Consider the same experiment again, with just one change. This time in the Before we are attempting to insert lines way down in the code module, by adjusting the number given in .insertlines Line:= by 100
Before:
'line 1
'Line 2
Sub LoopYinLinesTiddlyHiFoo()
4 Dim VBIDEVBAProj As Object
5 Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.codemodu le
6 Dim LineNo As Long, StartLine As Long, StopLine As Long
7 Let StartLine = VBIDEVBAProj.countoflines + 1: Let StopLine = StartLine + 4
8 For LineNo = StartLine To StopLine
9 VBIDEVBAProj.insertlines Line:=LineNo + 100, String:="'Line " & LineNo
10 Next LineNo
End Sub
The corresponding After , in terms of the added lines is exactly the same as before:
'line 1
'Line 2
Sub LoopYinLinesTiddlyHiFoo()
4 Dim VBIDEVBAProj As Object
5 Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.codemodu le
6 Dim LineNo As Long, StartLine As Long, StopLine As Long
7 Let StartLine = VBIDEVBAProj.countoflines + 1: Let StopLine = StartLine + 4
8 For LineNo = StartLine To StopLine
9 VBIDEVBAProj.insertlines Line:=LineNo + 100, String:="'Line " & LineNo
10 Next LineNo
End Sub
'Line 12
'Line 13
'Line 14
'Line 15
'Line 16

The point may still not be clear, so just to put in words again the issue:
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.
By choosing carefully the number of, in particular the variable StartLine , I am, however, able to predict the actual line number at which each code line is added.

DocAElstein
03-20-2018, 08:42 PM
Example
Post #3 Copy table contents to VBE module

The idea of these codes are to allow for a temporary storage of spreadsheet values to a code module.
_ One code will add a table of values to the end of a code module, and an extra start and end line will be added which contains range and date info. This code uses the selected range. So a range must be selected before running this code.
and
_ a second code can be used to paste those values back to the same range.
Optionally a date of entry can be given to search for, otherwise all table values are pasted in

The codes are somewhat detailed and inefficient. They work in many places “line by line”. There are some more simpler and more efficient codes here. http://www.eileenslounge.com/viewtopic.php?f=30&t=31395#p243002

Sub PubProliferous_Let_RngAsString__()
This code puts a selected range of values into the code module in which the code at the position of just after this coding. The table data values will be added to ( or taken from in following codes ) the module in which the code is run.
Here a brief walk through the code. There are more details in the 'comments
Rem 0 Sets for convenience, a variable to the code module in which the code is placed/ run from
Rem 1
A code module used for storing a table will be given the extension to its code name of "_txt" No special reason for doing this, I just thought it might be useful for later reference to know that the code module is being used in such a way. ( If no more table data is in the code module, then the extension , "_txt" , will be removed. This will be done , for example in following codes after the data is removed.)
Rem 2
Before running the code, a spreadsheet range should be selected. The range is copied to the clipboard, and the text of that put in a string variable, strIn
Rem 3
The string format is changes slightly to allow better display in this code ( and to aid in manipulation in the codes which re copy the data back to the spreadsheet, http://www.eileenslounge.com/viewtopic.php?f=30&t=31395#p242941
Rem 4
This adds an “extra line” to the start of the string with range information and current date, and an extra line at the end of the string with the same date. (I use date format of 10 digits as DD MM YYYY. ( This needs to be added to the data retrieving codes if looking for data from a specific date ) )
As demo example, say I copied a 2 row x 2 cell range, B2:C3 to the clipboard. Say the range looked like this
A B
C D
At this point in the routine, after Rem 4 , I will have in strIn , something of this approximate/pseudo form, ( say for a date of 12th December, 2018 ):

= " '_-20 12 2018 Worksheets("Tabelle2").Range("B2:C3") " & vbCr & vbLf & “|” & “A” & “|” & “B” & vbCr & vbLf & “|” & “C” & “|” & “D” & vbCr & vbLf & “ '_-20 12 2018 “
Rem 5
The above string is converted to an array by splitting by the & vbCr & vbLf & . So effectively , I would end up with something of this form , for the above example , a 4 element, 1 Dimensional array:
{ SpltRws(0) , SpltRws(1) , SpltRws(2) , SpltRws(3) }
where
SpltRws(0) = " '_-20 12 2018 Worksheets("Tabelle2").Range("B2:C3") "
SpltRws(1) = “|” & “A” & “|” & “B”
SpltRws(2) = “|” & “C” & “|” & “D”
SpltRws(3) = “ '_-20 12 2018 “


Alan

DocAElstein
12-21-2018, 09:21 PM
test test



askjfhsakjhfaskfhah



Example
Post #3 Copy table contents to VBE module (Post#4 Re Paste back to spreadsheet)
3) Copy table contents to VBE module

The idea of these codes are to allow for a temporary storage of spreadsheet values to a code module.
_ One code will add a table of values to the end of a code module, and an extra start and end line will be added which contains range and date info. This code uses the selected range. So a range must be selected before running this code.
and
_ a second code can be used to paste those values back to the same range.
Optionally a date of entry can be given to search for, otherwise all table values are pasted in

The codes are somewhat detailed and inefficient. They work in many places “line by line”. There are some more simpler and more efficient codes here. http://www.eileenslounge.com/viewtopic.php?f=30&t=31395#p243002

Sub PubProliferous_Let_RngAsString__()
This code puts a selected range of values into the code module in which the code at the position of just after this coding. The table data values will be added to ( or taken from in following codes ) the module in which the code is run.
Here a brief walk through the code. There are more details in the 'comments
Rem 0 Sets for convenience, a variable to the code module in which the code is placed/ run from
Rem 1
A code module used for storing a table will be given the extension to its code name of "_txt" No special reason for doing this, I just thought it might be useful for later reference to know that the code module is being used in such a way. ( If no more table data is in the code module, then the extension , "_txt" , will be removed. This will be done , for example in following codes after the data is removed.)
Rem 2
Before running the code, a spreadsheet range should be selected. The range is copied to the clipboard, and the text of that put in a string variable, strIn
Rem 3
The string format is changes slightly to allow better display in this code ( and to aid in manipulation in the codes which re copy the data back to the spreadsheet, http://www.eileenslounge.com/viewtopic.php?f=30&t=31395#p242941
Rem 4
This adds an “extra line” to the start of the string with range information and current date, and an extra line at the end of the string with the same date. (I use date format of 10 digits as DD MM YYYY. ( This needs to be added to the data retrieving codes if looking for data from a specific date ) )
As demo example, say I copied a 2 row x 2 cell range, B2:C3 to the clipboard. Say the range looked like this
A B
C D
At this point in the routine, after Rem 4 , I will have in strIn , something of this approximate/pseudo form, ( say for a date of 12th December, 2018 ):

= " '_-20 12 2018 Worksheets("Tabelle2").Range("B2:C3") " & vbCr & vbLf & “|” & “A” & “|” & “B” & vbCr & vbLf & “|” & “C” & “|” & “D” & vbCr & vbLf & “ '_-20 12 2018 “
Rem 5
The above string is converted to an array by splitting by the & vbCr & vbLf & . So effectively , I would end up with something of this form , for the above example , a 4 element, 1 Dimensional array:
{ SpltRws(0) , SpltRws(1) , SpltRws(2) , SpltRws(3) }
where
SpltRws(0) = " '_-20 12 2018 Worksheets("Tabelle2").Range("B2:C3") "
SpltRws(1) = “|” & “A” & “|” & “B”
SpltRws(2) = “|” & “C” & “|” & “D”
SpltRws(3) = “ '_-20 12 2018 “
Rem 6
We examine the dimensions of the array and determine which lines will be used at the end of the code module
Rem 7
'7a) '7d) The extra start and end lines are added as simple lines.
'7b) This is the main loop for inserting/(actually adding**) data lines
'7c) this second inner loop builds up the actual line to be outputted from the columns/cells: The row is first split into each cell/column , and then a string of all cell/columns rebuilt. This is done so that we can add some formatting to each cell/column. In this code we effectively add each cell/column string into a fixed length string variable, so that in the VB editor it looks a bit neater with the cell/columns being of equal with regardless of how many characters are in each cell/column
**Note: As discussed in the last post ( ,asqhfkhhsfhakfhfh ) , we use the code line of this form:
___.insertlines Line:=____, String:=”____”
We actually use a value in the argument Line:=____ which is 1 greater than the last line. It is not possible to “Insert” a line where no line currently is. But for any value 1 or more greater than the last line, the code line appears to add** a new line. That line will then eventually / indirectly become the line number which is 1 greater than the last line number. So we achieve what we want, but are not doing it as directly as it might appear at first glance:- We can only insert lines at up to and including the last current line. If we try to insert anywhere above the last current line, then the ___.insertlines _ will add** a new line directly after the last current line.

_.___________________

Example of code run.
Consider that this spreadsheet range is highlighted,…._
_____ Workbook: Uebersicht Aktuelle.xls ( Using Excel 2007 32 bit )
Row\Col
A
B
C
D
E
F

249224 11 2018GHGT2136.253030.04


249325 11 2018GHGT


249426 11 2018GHGT2150.175151.1


249527 11 2018GHGT2146.473131
Worksheet: Tabelle1
_... and then run the code Sub PubProliferous_Let_RngAsString__()
After doing this, you should see this towards the end of the code module in which the code is placed

'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

'_-21 12 2018 Worksheets("Tabelle1").Range("$A$2492:$F$2495")
'_-24 11 201 | GH | GT | 2136.25 | 30 | 30.04
'_-25 11 201 | GH | GT | | |
'_-26 11 201 | GH | GT | 2150.17 | 51 | 51.1
'_-27 11 201 | GH | GT | 2146.47 | 31 | 31
'_-21 12 2018

You will note that you have lost a digit in the column A dates – the 8 in 2018 is missing. This is because the formatting is set to 9 characters by this variable
__TabulatorSyncrenator = "123456789" ' any lengthed string will do
You can overcome that problem by increasing the character length of that variable by 1 digit. Any character will do, for example
__TabulatorSyncrenator = "1234W56789"


Re run the code on the same range and you will now see this:
Why Tabulator SinkCranartor.JPG : https://imgur.com/i6VsFRP
( TabulatorSyncrenator = "12345Y6789" )

End Sub

'_-21 12 2018 Worksheets("Tabelle1").Range("$A$2492:$F$2495")
'_-24 11 201 | GH | GT | 2136.25 | 30 | 30.04
'_-25 11 201 | GH | GT | | |
'_-26 11 201 | GH | GT | 2150.17 | 51 | 51.1
'_-27 11 201 | GH | GT | 2146.47 | 31 | 31
'_-21 12 2018

'_-21 12 2018 Worksheets("Tabelle1").Range("$A$2492:$F$2495")
'_-24 11 2018 | GH | GT | 2136.25 | 30 | 30.04
'_-25 11 2018 | GH | GT | | |
'_-26 11 2018 | GH | GT | 2150.17 | 51 | 51.1
'_-27 11 2018 | GH | GT | 2146.47 | 31 | 31
'_-21 12 2018




Codes are here:
Well they will be, you betcha




_._____________________-

In the next posts we consider ways to Get at that data range in a code module, and re paste it into the spreadsheet at the original range
ext posts we consider ways to Get at that data range in a code module, and re paste it into the spreadsheet at the original range

DocAElstein
12-21-2018, 09:35 PM
<strike> scratch left testie </strike>

<marquee behavior="scroll" direction="left">Scrolling testie...</marquee>


Example
Copy table contents to VBE module Post#4 Re Paste back to spreadsheet
4) Paste range values held in VBE module back to

So the last code, having been run when a range, such as this was selected, …._ _____ Workbook: Uebersicht Aktuelle.xls ( Using Excel 2007 32 bit )
Row\Col
G
H

2503223.38FH


2504194.67FH
Worksheet: Tabelle1_... would result in the '_-commented lines like these appearing at the last rows of the code module in which that code was run
End Sub

'_-23 12 2018 Worksheets("Tabelle1").Range("$G$2503:$H$2504")
'_-223.38 | FH
'_-194.67 | FH
'_- EOF 23 12 2018In this post a code is presented for re pasting the original data values back into the original spreadsheet range. ( The code also removes the data from the code module )

Code description.
It is a bit difficult to give a detailed walk through description as the code goes around in circles ( it does Do Loops) a bit. So here is just a general description of the full code:
It is convenient to work backwards, deleting the lines in the VB Editor as we go: Unlike in a spreadsheet we always know in a code module that the last line is the last line of data, in other words the pseudo code module sheet has a last cell at the last data entry: We don’t have empty rows. Rows only exist as data is/ was entered
__1A Main outer Loop keeps going While we are not at the End of a routine ===============
_____Immediately within that is another Loop which keeps going While we have not reached the start line of a data section ( A start of a data section will look like this sort of form '_-21 12 2018 Worksheets("Sht_1").Range("$B$15:$D$16") )

It is not obvious from the routine layout, but the main action which is done first at every loop and initially after the routine begins is that which does the reading of the next line back from the end, in other words the current last line
____Let ReedLineIn = VBIDEVBAProj.Lines(StartLine:=VBIDEVBAProj.countof lines, Count:=1)
Immediately after that, the code will end if a routine End _____ type statement was read, or Else the line is deleted. Initially when the code starts we are directed immediately to this lower part of the code by virtue of
____If ReedLineIn = "" Then
'for an empty line we do nothing apart from having already deleted it ( for all but the first time here at the code start)
At this lower routine section, a code line is read, we will quickly leave the routine If we have read an End __ type statement. This is because the Loop While condition to keep looping is no longer met because we set the Boolean variable, EndOFSub , to True:

Let ReedLineIn = VBIDEVBAProj.Lines(StartLine:=VBIDEVBAProj.countof lines, 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
Loop While EndOFSub = False '
End Sub

If we do not have the ReedLineIn = "" condition then we are at the part where things are done in each inner loop, ----|

The first thing that is done is to see
____If we have got, ( as a result of looping backwards “down” the code module occupied lines), to the point of a start section of a data section which will have a code line something like '_-22 12 2018 Worksheets("Tabelle1").Range("$A$2515") If that is the case Then we are at the ' Section to prepare data for, and to do, the paste out of a data value range
Various manipulation is then done to convert the collected information so far ( in String variable arrOut ) , into a form which will paste out to a spreadsheet range from the clipboard
____The Else situation here is ( If we are not at an end line of the data range ( like '_- EOF 22 12 2018 ) ) is simply to collect all the range text as a continual string, held in variable arrOut
____ We have now arrived at the end of doing things in the inner loop, and the code goes on to reading the next line, then checking for If at an End __ of routine, Else then deleting the line and
____We are now at the point of moving to the next loop of action to analyse and possibly do something with the last copied line held now in string variable ReedLineIn

_.___________________-

4b) Multi range data
The same code will paste out many ranges held in the code module. All ranges will be pasted back to their original spreadsheet range, and be removed from the code module
So for example , with this data in the same code as the routine Sub PubProliferous_Get_Rng__AsString() , will result in the following worksheet ranges being filled, (and also the data from the code module will be removed)
Worksheet "Tabelle1" , Range F2504:I2505
Worksheet "Tabelle2" , Range B392:D394
Worksheet "Globies" , Range F24:G25

Loop While EndOFSub = False ' ================================================== ==============
End Sub

'_-23 12 2018 Worksheets("Tabelle2").Range("$B$392:$D$394")
'_-gramms | Kcal | Fett
'_-300g | 198Kcal | 0
'_-51g | 183,09K | 4,08
'_- EOF 23 12 2018

'_-23 12 2018 Worksheets("Tabelle1").Range("$F$2504:$I$2505")
'_-41.09 | 194.67 | FH | WH
'_-55.07 | 233.32 | FH | WH
'_- EOF 23 12 2018

'_-23 12 2018 Worksheets("Globies").Range("$F$24:$G$25")
'_-GF F | GG G
'_-EiweiƟ | Koh
'_- EOF 23 12 2018After running the routine, Sub PubProliferous_Get_Rng__AsString() , the end of that code module will then look like this:
Loop While EndOFSub = False ' ================================================== ==============
End Sub



_.______________

Final routine is here:



In the next post, a slightly different routine will be presented. This routine will
not remove the range value data in the code module
and
only look for data corresponding to a given date.

DocAElstein
12-23-2018, 04:46 PM
Test


مرحبا كيف حالك

Example
Copy table contents to VBE module Post#4 Re Paste back to spreadsheet
5) Paste range values held in VBE module back to spreadsheet ( without deleting values from code module and selection of data range based on date


Post #5 Sub PubeProFannyTeas__GLetner("____")

This posts differs from that in the previous post in that it searches for a data range held towards the end of a code module, based on a given date.
The date should have a 10 digit “DD MM YYYY” type format.
For example, for the 23rd December, 2018 a calling code would look like this

Sub TestCall()
Call PubeProFannyTeas__GLetner("23 12 2018")
End Sub


If the following data…._
Next Cnt ' next date range
End Sub

'_-23 12 2018 Worksheets("Tabelle1").Range("$G$2513:$H$2514")
'_-91.01 | FH
'_-163.73 | FH
'_- EOF 23 12 2018

'_-23 12 2018 Worksheets("Tabelle1").Range("$I$2513:$J$2514")
'_-WH | MH
'_-WH | MH
'_- EOF 23 12 2018_.... were in the code module, ( for example after running code, Sub PubProliferous_Let_RngAsString__() ), then running the above would result in the range…___
WH MH
WH MH
_... being pasted into worksheet with name “Tabelle1” starting top left at cell I2513. In other words the result would be in the worksheet something like:
_____ Workbook: Uebersicht Aktuelle.xls ( Using Excel 2007 32 bit )
Row\Col
I
J

2513WH MH


2514WH MH
Worksheet: Tabelle1
Notes:
_ Only values are pasted, so the cells in the above example must have been previously in those text color formats
_ For more than one matching date, the range furthest down will be used by the code

Code description: (Sub PubeProFannyTeas__GLetner(ByVal strDte As String) )

Rem 0 Code module as object
As in previous codes, for convenience an object variable is set to the active code window.

Rem 1 complete data range from end of code module
'1a) This section effectively progresses “back down” the code window until an end routine is encountered and thereby counts to determine the number of data rows/lines
'1b) A similar code line is used as previously for reading single lines, but by choosing more than 1 in the second argument a long single string, strIn , is returned with a vbCr & vbLf pair which are pseudo between*** the lines of data. ( This vbCr & vbLf pair seems to be characteristically “ there “ at the next line which is not in use or counted, such that it gets “tacked on” the start of new lines***
A major characteristic of this routine is the manipulation of that single string using various VBA Strings collections functions.
At this point the string might include more than one data range.
'1c) Because we have a “line free” between data ranges held in the code window, this means that the string at these positions will have the usual pair of vbCr & vbLf pair, but because no data is on the line next part of the string will be the next vbCr & vbLf pair. Hence we have characteristically at this position vbCr & vbLf & vbCr & vbLf pair. Using vbCr & vbLf & vbCr & vbLf as separator is therefore a convenient way to split the complete string into an array where each array element is a single string of a complete data range

Rem 2 manipulation of found date range
We start here with a found range ( in a single long string format ) currently in the chosen array of ranges, and for no particular reason put that array element into a simple string variable. (There is no check for no matching date. The code will simple end after all ranges have been looped through.)
'2a) The range information at the start of the string is easy to obtain from simple string manipulation , - in the 'comments example and detail is given )
'2b)
Further manipulation brings the string into the typical for which we find is what Excel gives and takes to paste in a range from the clipboard, For example for a 2 row x 3 column range like this…_
Cell1 Cell2 Cell3
_cell4 cell5 cell6
_

_... has a simple long single string form of
“Cell1 & vbTab & Cell2 & vbTab & Cell3 & vbCr & vbLf & cell4 & vbTab & cell5 & vbTab & cell6 & vbCr & vbLf”

Rem 3 range output to worksheet range
The final prepared range string is given to a “Data object” which had a method which we use to put the string into the clipboard.
A simple Paste is then all that is needed to put the data range of values into the worksheet.








Rem Ref
' http://www.eileenslounge.com/viewtopic.php?f=30&t=31395
' http://www.cpearson.com/excel/vbe.aspx
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





2513 WH MH
2514 WH MH
Worksheet: Tabelle1
Notes:
_ Only values are pasted, so the cells in the above example must have been previously in those text color formats
_ For

مرحبا كيف حالك

مرحبا كيف حالك

DocAElstein
04-20-2019, 12:29 PM
Testing solutions and tables for this Thread,
http://www.excelfox.com/forum/showthread.php/2330-Fill-Column-Based-on-Actual-Time?p=11124#post11124


_____ Workbook: Data Sheet.xls ( Using Excel 2007 32 bit )
Row\Col
A
B
C
D
E
F
G
H

1ChannelDateAdStartMidBreakBreak_StartBreak_EndHou r


149A NEWS
15. Nov 17
19:59:09Casual
19:50:23
20:00:05
19


150A NEWS
15. Nov 17
20:19:12Mid Break-1
20:19:08
20:24:07
20


151A NEWS
15. Nov 17
20:19:32Mid Break-1
20:19:08
20:24:07
20


152A NEWS
15. Nov 17
20:19:49Mid Break-1
20:19:08
20:24:07
20


153A NEWS
15. Nov 17
20:20:01Mid Break-1
20:19:08
20:24:07
20


154A NEWS
15. Nov 17
20:20:47Mid Break-1
20:19:08
20:24:07
20


155A NEWS
15. Nov 17
20:21:10Mid Break-1
20:19:08
20:24:07
20


156A NEWS
15. Nov 17
20:21:20Mid Break-1
20:19:08
20:24:07
20


157A NEWS
15. Nov 17
20:21:30Mid Break-1
20:19:08
20:24:07
20
Worksheet: Sheet2



_____ Workbook: Data Sheet.xls ( Using Excel 2007 32 bit )
Row\Col
A
B
C
D
E

1DateChannelsstart timeNew Time


2
11.15.2017
A NEWS
20:29:00
20:19:12


3
11.15.2017
A NEWS
20:59:00
20:21:20


4
11.15.2017
A NEWS
21:29:00
21:13:49


5
11.15.2017
A NEWS
21:59:00
21:36:30


6
11.15.2017
A NEWS
22:29:00
22:27:36


7
11.15.2017
A NEWS
22:59:00
22:48:51


8
11.15.2017
A NEWS
23:29:00
23:28:33


9
11.15.2017
A NEWS
23:58:00
23:29:55


10
11.16.2017
A NEWS
20:29:00
20:23:02


11
11.16.2017
A NEWS
20:59:00
20:50:04


12
11.16.2017
A NEWS
21:29:00
Worksheet: Sheet1


test....

Row\Col
A
B
C
D
E
F
G
H
I
J
K
L
M

1DateChannelsstart timeNew Time


2
11.15.2017
A NEWS
20:29:00
20:19:12


3
11.15.2017
A NEWS
20:59:00
20:21:20Other lines from From sheet2:-


4
11.15.2017
A NEWS
21:29:00
21:13:49A NEWS
15. Nov 17
21:13:49Mid Break-1
21:12:55
21:15:05
21


5
11.15.2017
A NEWS
21:59:00
21:36:30A NEWS
15. Nov 17
21:36:30Mid Break-2
21:35:31
21:40:14
21


6
11.15.2017
A NEWS
22:29:00
22:27:36A NEWS
15. Nov 17
22:27:36Mid Break-1
22:26:54
22:33:55
22


7
11.15.2017
A NEWS
22:59:00
22:48:51A NEWS
15. Nov 17
22:48:51Mid Break-2
22:47:02
22:54:02
22


8
11.15.2017
A NEWS
23:29:00
23:28:33A NEWS
15. Nov 17
23:28:33Mid Break-1
23:26:54
23:34:47
23


9
11.15.2017
A NEWS
23:58:00
23:29:55A NEWS
15. Nov 17
23:29:55Mid Break-1
23:26:54
23:34:47
23


10
11.16.2017
A NEWS
20:29:00
20:23:02A NEWS
16. Nov 17
20:23:02Mid Break-1
20:22:21
20:24:03
20


11
11.16.2017
A NEWS
20:59:00
20:50:04A NEWS
16. Nov 17
20:50:04Mid Break-3
20:46:06
20:53:37
20


12
11.16.2017
A NEWS
21:29:00

DocAElstein
04-20-2019, 02:38 PM
I am stumbling to find the logic to match up these rows....

_____ Workbook: Data Sheet.xls ( Using Excel 2007 32 bit )
Row\Col
A
B
C
D
E
F
G
H
I
J
K
L
M

1DateChannelsstart timeNew TimeOther lines from From sheet2:-


2
11.15.2017
A NEWS
20:29:00
20:19:12A NEWS
15. Nov 17
20:19:12Mid Break-1
20:19:08
20:24:07
20


3
11.15.2017
A NEWS
20:59:00
20:21:20A NEWS
15. Nov 17
20:21:20Mid Break-1
20:19:08
20:24:07
20


4
11.15.2017
A NEWS
21:29:00
21:13:49A NEWS
15. Nov 17
21:13:49Mid Break-1
21:12:55
21:15:05
21


5
11.15.2017
A NEWS
21:59:00
21:36:30A NEWS
15. Nov 17
21:36:30Mid Break-2
21:35:31
21:40:14
21


6
11.15.2017
A NEWS
22:29:00
22:27:36A NEWS
15. Nov 17
22:27:36Mid Break-1
22:26:54
22:33:55
22


7
11.15.2017
A NEWS
22:59:00
22:48:51A NEWS
15. Nov 17
22:48:51Mid Break-2
22:47:02
22:54:02
22


8
11.15.2017
A NEWS
23:29:00
23:28:33A NEWS
15. Nov 17
23:28:33Mid Break-1
23:26:54
23:34:47
23


9
11.15.2017
A NEWS
23:58:00
23:29:55A NEWS
15. Nov 17
23:29:55Mid Break-1
23:26:54
23:34:47
23


10
11.16.2017
A NEWS
20:29:00
20:23:02A NEWS
16. Nov 17
20:23:02Mid Break-1
20:22:21
20:24:03
20


11
11.16.2017
A NEWS
20:59:00
20:50:04A NEWS
16. Nov 17
20:50:04Mid Break-3
20:46:06
20:53:37
20


12
11.16.2017
A NEWS
21:29:00
Worksheet: Sheet1



Testing

excelfox