Skip to main content


Showing posts with the label Macro

Excel Macro get cell values but skip other rows

Raw data that comes in pattern is easy to handle for further processing.
For example, if you have a data that has final value in every 7th row, so basically 1 to 6 is not needed and 7th row is needed, likewise 8th row to 13th row is not needed and 14th row is needed and the pattern goes on that every 7th row is the final data from the previous 6 rows.
If the pattern continues, it will be like: 1-6, 7 final value, 7 -13, 14 final value, 15 to 20, 21 final value, 22 to 27, 28 final value and the pattern goes on up to hundreds or thousands. It will be time consuming to get every 7th row manually.
For graphical representation it will be like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
From the image above every 7th row (green color) is needed and the rest is discarded.
Other issue comes in if the data has to be processed further in another sheet, doing this manually is so tedious and prone to error.
This is where VBA or Excel macro comes into play and simplify the process. The “step” keyword in VBA or even VB…

Outlook does not display picture

Have you received an email saying please find the picture below, but the picture is on the attachment not on the body of email.

Or sending out a nice an beautiful layout of graphics hoping to impress a colleague or client only to find out that the the graphics doesn't display correctly in Outlook or either in the mobile phone.

HTML Tables has been a big help for web designers or developers before the CSS era or other good platforms at this time.

Well, if picture is not displaying properly in Outlook or mobile phone. Embedding or inserting the picture in a Table, seems to be a good quick solution in inserting pictures via Outlook and it will display properly in mobile phone also.

When composing email in Outlook, click on the Insert option and click on insert table. If sending two pictures, you can insert a two rows or two columns and insert the picture on each row or column.

After sending out the email, check the email in Outlook or mobile phone and if everything goes okay the pic…

VB.Net remove line feed or new line

In or any programming language, if the program requires getting data from external programs, results or data from third party software that needs to be processed  may or may not have expected desired output.

For example, getting a string from a third party software. String is quite straight forward and it's quite basic.

But the issue arises,  if the desired output requires a specific string or text and other text should be discarded or deleted. Regex or any other methods might help on getting the specific text or data.

One basic issue, if the string needs to be formatted in one line but a line feed or a new line keeps breaking the line.

The first instinct that I think of, is to use "Trim" function but it doesn't solve the issue. Trim, Ltrim or Rtrim just delete spaces but it doesn't delete line feed.

In VB.Net a line feed can easily be removed by this code snippet below:

Dim strNoLineFeed As String = String_with_Line_Feed.Replace(vbCr, "").Replac…

Excel VBA replace first or last character

Excel VBA code below will replace the first or last character of the cell value.

Use a test workbook with dummy data, to test the VBA code.

Works fine on Excel 2010.

Sub replaceChar()
'Replace Last Character

Dim i, ilength As Integer
Dim strCellValue, yCutString, zValue As String
Dim iRow, myColumn As Long

'specify the column where the values will be changed
myColumn = 2

'get the last row
iRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row

For i = 1 To iRow
On Error Resume Next

strCellValue = Cells(i, myColumn).Value
ilength = Len(strCellValue) - 1

'left - will replace last character on the string
yCutString = Left(strCellValue, ilength)

' LastChar is the string that will be added to the end of the cell value
'Replace this with any desired value
zValue = yCutString + "LastChar"

'Display the value of the processed string
'press ctrl+break to stop the loop
MsgBox zValue

'uncomment this line to replace the value with the processed string