Saturday, November 16, 2013

Check if there are charts on a given worksheet and if yes, delete them(VBA-Excel)


'This code checks if there are any charts on a specific sheet and, if yes, deletes them:

Sub know_if_there_are_charts()
Dim ws As Worksheet

If ws.ChartObjects.Count <> 0 Then
ws.ChartObjects.Delete

End If

End Sub

Divide the axis values by 1000 (VBA-Excel)


This code changes the unit of a given axis of a chart to thousand, i.e. divide the units by 1000

Sub Divide_axis_values_by_1000()
    ActiveChart.Axes(xlValue).DisplayUnit = xlThousands
End Sub

Tuesday, October 15, 2013

Installing Linux in Windows 8

As I told on this post: "The selected languages", one of my selected languages to learn how to program was Unix. However it took me a while to finally find a good Unix run-environment for my windows pc.

On the first glance, the best option would be the installation of Linux OS on a virtual box. That's why I have been trying and trying again to make the oracle virtual box work on my windows 8 but it has been in vain.
As my thirst for learning how to program in Unix is kind of out of control LOL LOL LOL, I found a better option: the Cygwin Terminal.

If you have the windows 8 and want to learn Unix I think that the installation of Cygwin is definitely a very good option. It is very fast and allows almost all the commands that Linux have. Try it!


Please check this video that I did to explain you step by step how to install it. The video has Portuguese audio but there are subtitles in English.


Thursday, October 10, 2013

How to enable the content of a workbook?(Excel-VBA)

Each time we open with VBA an excel file, coming from another person, one of the most annoying things is the fact of having to select the "enable content" option.

However, did you know that you can get rid of that security warning directly in VBA? Just write this following code,defining as true the update of the links (the argument of Open method), so for example:

















With the code above we open the file1.xls and we get rid of the update links security warning! ;) A very useful instruction in my point of view!




Sunday, September 22, 2013

How to change the background color of a cell in VBA? (VBA-EXCEL)

The easiest way to change the background color of a cell in VBA is using the color index, so if we want to change the color of cell A1 to red we should write:

Sub change_color()

Activesheet.range("a1").interior.colorindex=3

End sub

I leave here to you the color palette with the respective numbers of the colors, in case you want to color a cell but not with red :)


Thursday, September 19, 2013

How to change the chart type of just one of the series on a chart.-VBA(excel)

Sometimes we have a chart with different variables, if we want the different variables to appear on the same chart but with a different chart type we can do it on VBA:

Just select the chart, write this code and run it:

Sub Chart()

ActiveChart.ChartType =xlXYScatterSmooth
ActiveChart.SeriesCollection(1).ChartType = xlXYScatterLines

End Sub

In this example, we have as result a line to show the evolution of the variable 1, and just points to show the behaviour of the rest of the series. Easy, isn't it?

Tuesday, September 3, 2013

Set a Range (VBA-Excel)

One of the basic steps to solve a lot of problems on Excel is to set a range in order to use it and reuse it as many times as you like during a procedure (Macro).

Sub SetaRange()

Dim Rng as Range

Set Rng=Range("A1:C10")

End Sub

With the code above you set a range named Rng (you can choose a different name if you prefer), consisting of all the cells from A1 to C10 on the Active Sheet.