Code:Dim llCountLines As Long Dim ilSanityCheck As Integer Dim llEndLine As Long Dim procKind As Long 'Set up a codepane object for where the cursor is in the sub. For this example, where you placed it. Setting a variable makes the code more readable and a mite shorter instead of using Application.VBE.ActiveCodePane all the time. Set olPane = Application.VBE.ActiveCodePane ' Setting a variable makes the code more readable and a mite shorter instead of using Application.VBE.ActiveCodePane all the time. ' GetSelection returns the position info for our selection and places those row and column numbers in our chosen variables olPane.GetSelection Startline:=llSRow, startcolumn:=llSCol, Endline:=llERow, Endcolumn:=llECol ' This is a bit of a wierdo: ProcOfLine function returns the name of the Procedure for the given line. We can use for example the returned selection start row. The wierd thing is that the second srgument is returned to us, that is to say that returns the number VBA uses to identify the procedure type. For ProcBodyLine, ProcCountLines, and ProcStartLine, we need the procedure name. PocOfLine will return it. For those functions, we also need to know the pk (procedure kind) or type. ProcOfLine returns that as well. In fact, it's the only procedure that will give us the proc type. Once we have it, we can plug it into the other calls. This makes where you put this call important. It has to be before the calls that need procKind Let slProcName = olPane.CodeModule.ProcOfLine(llSRow, procKind) ' Let llLine1 = olPane.CodeModule.ProcBodyLine(slProcName, procKind) ' Get the procedure "start" line: the line on which the Declaration/Definition is for that procedure name, slProcName Let llCountLines = olPane.CodeModule.ProcCountLines(slProcName, procKind) ' Get the count of lines in this procedure. In this case ..... Let llStartLine = olPane.CodeModule.ProcStartLine(slProcName, procKind) ' Get the start line of the procedure. In this case ... Let llEndLine = llStartLine + llCountLines - 1 ' this we calculate
Code:Option Explicit Sub DumDim() For Cnt = 1 To 10 Next Cnt Dim Cnt As Long End Sub
Code:Sub DumDim() Dim Cnt As Long For Cnt = 1 To 3 Dim Count As Long Count = Count + 1 ' count value will be 3 Next Cnt MsgBox Prompt:=Count: Debug.Print Count End Sub
Worksheet: BluePrint
This must be correct Time Format This must be Correct Date Format
This must be correct Time Format This must be Correct Date Format
Dim a! ' same as Dim a as Short
Dim b@ ' same as Dim b as Currency
Dim c# ' same as Dim c as Double
Dim d$ ' same as Dim d as String
Dim e% ' same as Dim e as Integer
Dim f& ' same as Dim f as Long
[Code]Dim a! ' same as Dim a as Short
Dim b@ ' same as Dim b as Currency
Dim c# ' same as Dim c as Double
Dim d$ ' same as Dim d as String
Dim e% ' same as Dim e as Integer
Code:Dim strA As String, strB As String Dim lA As Long, Lr As Long ' Or maybe this ??? Dim strA$, strB$ Dim lA&, Lr& ' ' https://bytes.com/topic/visual-basic/answers/643371-declaration-shortcuts ' https://stackoverflow.com/questions/28238292/declaring-variables-in-vba ' http://www.excelforum.com/excel-programming-vba-macros/1100751-excel-vba-to-copy-and-paste-from-horizontal-to-vertical-format-2.html#post4194972 ' https://www.excelforum.com/excel-programming-vba-macros/1116127-avoiding-variants-multiple-declarations-per-line-assign-variants-to-all-but-last-variable.html#post4256569 Dim a! ' same as Dim a as Short Dim b@ ' same as Dim b as Currency Dim c# ' same as Dim c as Double Dim d$ ' same as Dim d as String Dim e% ' same as Dim e as Integer Dim f& ' same as Dim f as Long
'
' https://bytes.com/topic/visual-basic...tion-shortcuts
' https://stackoverflow.com/questions/...riables-in-vba
' http://www.excelforum.com/excel-prog...ml#post4194972
' https://www.excelforum.com/excel-pro...ml#post4256569
Dim a! ' same as Dim a as Short
Dim b@ ' same as Dim b as Currency
Dim c# ' same as Dim c as Double
Dim d$ ' same as Dim d as String
Dim e% ' same as Dim e as Integer
Dim f& ' same as Dim f as Long
Code:lnglProcCountLines, _ lnglModuleProcEndLine Stop ' You got stopped - now go up there and do a bit of harvesting ' *********************************************************************** End Sub
_____ Workbook: NeuProAktuelleMakros.xlsm ( Using Excel 2007 32 bit )
Worksheet: Leith2
Row\Col F G 39 40 µg% Empholen 41 0 42 0






Reply With Quote
Bookmarks