Hello
Can someone refine the below code inorder to get Exact Amount of SPACE between 2 strings
Tried to create function but somehow could not succeed.
I want exact SPACE between Two Strings. So the alignment comes perfectly between Two Strings in Textbox
Somehow the alignment between two strings is not properly aligned with below code
NimishK
Can someone refine the below code inorder to get Exact Amount of SPACE between 2 strings
Tried to create function but somehow could not succeed.
I want exact SPACE between Two Strings. So the alignment comes perfectly between Two Strings in Textbox
Somehow the alignment between two strings is not properly aligned with below code
VBA Code:
Option Explicit
Private Sub UserForm_Initialize()
Dim strDescp(4) As String, strQuot(4) As String
Dim strHeader As String
Dim i As Integer, gapSpc As Integer
Dim strData As String
strHeader = "Description" & Space(10) & "Quoted"
strDescp(1) = "The Brown Fox"
strDescp(2) = "quickly Jumped"
strDescp(3) = "over the"
strDescp(4) = "Lazy dogs"
strQuot(1) = "Yes"
strQuot(2) = "No"
strQuot(3) = "No"
strQuot(4) = "Yes"
strData = strHeader & vbCrLf
For i = 1 To UBound(strDescp)
gapSpc = NewTotSpaces((strDescp(i)), 15, 8)
strData = strData & strDescp(i) & Space(gapSpc) & strQuot(i) & vbCrLf
Next i
TextBox1.Text = TextBox1.Text & strData
End Sub
Public Function NewTotSpaces(strChar As String, ByVal maxStrLen As Integer, extraSpc As Integer) As Integer
Dim strLen As Integer
Dim newPos As Integer, i As Integer, rMangSpc As Integer, exactSpc As Integer
strLen = Len(strChar)
If strLen >= maxStrLen Then
rMangSpc = maxStrLen 'strLen
exactSpc = (rMangSpc - maxStrLen) 'rMangSpc '+ extraSpc
NewTotSpaces = exactSpc
Else
If strLen < maxStrLen Then
rMangSpc = maxStrLen - strLen
exactSpc = rMangSpc + extraSpc
NewTotSpaces = exactSpc
End If
End If
End Function
Last edited: