Archive for the ‘Strings’ Category

Aligning strings within a fixed width

With the functions below you can align a string (left, center or right) within a fixed width, this might be useful when you e.g. create reports with fix-width column formats. Function AlignLeft(varItem As Variant, intWidth As Integer) As String Dim strResult As String, i As Integer strResult = CStr(varItem) i = intWidth – Len(strResult) If [...]

Split a string and return any individual part

This function splits a character separated string into its indivual parts and returns any given part. The function can also be used as a worksheet function. The function will only work in Excel 2000 or later. Function GetStringPart(strInput As String, strDelimiter As String, _ intPart As Integer) As String Dim varStrings As Variant varStrings = [...]

Use text and numbers in the same cell

By using text and numbers from several different cells in the same cell you will be able to present your worksheet results in a nice way. To combine the results from two or more cells in one cell, you will have to use the &-function between the different expressions in the formula. When you combine [...]

Convert negative values treated as text

When you import numbers from data sources outside Excel it sometimes happens that the negative values is treated as text if they have the minus sign after the value. With the macro below you can convert these negative numbers to a valid negative value Excel can perform calculations with: Sub ConvertNegativeNumbers() Dim cl As Range [...]