Quick Transposer


A post from a Pistonhead member in need :

Hopefully someone can help!

I have a list of approx 50000 numbers in ‘Column A’ of spreadsheet. I need to split this list into batches of 1000, populated into Column B onwards.

Anyone with some VBA skill got any ideas? Thanks in advance!

 
My reply :
 
Sub QuickTranspose()

    Dim rng As Range
    Dim StartRowNum As Long
    Dim EndRowNum As Long
    Dim ColumnOffsetCounter As Long
    Dim GroupSize As Long
    Dim v
    Dim i As Long
    Dim TotalRows As Long
    GroupSize = 1000
    TotalRows = 50000
    
    'Dirty but without range names etc you just need to get the
    'selected cell to be the first one in the list
    Set rng = Application.Selection
    StartRowNum = rng.Rows.Row
    For i = 0 To TotalRows / GroupSize
        EndRowNum = StartRowNum + GroupSize - 1
        v = Range("A" & StartRowNum & ":A" & EndRowNum).Value
        Range(rng.Offset(0, i + 1), rng.Offset(GroupSize - 1, i + 1)).Value = v
        StartRowNum = EndRowNum + 1
    
    Next i
End Sub
Categories: Uncategorized

Triskaidekaphobia! Or in English: Microsoft Excel Team’s fear of 13.


So today when I saw something that look like this it made me smile:

Public Enum ExcelVersionEnum
    Excel4 = 4
    Excel95 = 7
    Excel97 = 8
    Excel2000 = 9
    Excelxp = 10
    Excel2003 = 11
    Excel2007 = 12
    Excel2010 = 14    'Triskaidekaphobia!
End Enum

There is no Excel version 13.  I of course only just found this out when I encountered Excel 2010 which, I blush to admit, I have not downloaded from TechNet yet and played with.

Triskaidekaphobia (from Greek tris meaning “3,” kai meaning “and,” and deka meaning “10”) is fear of the number 13; it is a superstition and related to a specific fear of Friday the 13th, called paraskevidekatriaphobia or friggatriskaidekaphobia.

Source : en.wikipedia.org/wiki/Triskaidekaphobia

Read more…

G Challenge III – Practice Excel VBA Interview question – Watch face maths


I have heard of this question coming up a little bit in all sorts of technical interviews so I thought I would set it as a G Challenge.

Question:

“Please tell me what you would implement to tell me the angle between then hands on a watch face at any given time of the day.  Please show your working and use these examples.”

6:00, 3:00, (lets make this non trivial now ) 9:15, 1:30 12:50,  3:20.

Answer Style:

It is up to you how you go about answering this, but I would try this in two stages. 

  1. Have a pen and paper and go about it as if you were in an interview, then :
  2. Actually try to write some VBA for a spreadsheet that goes about doing it.  Esp if you can call it from the sheet so your function returns the answer from an Excel Date Time entered in a cell.

Extra Homework:

  • Could you write this as a VB dll, C++ dll, C# XLL etc?
  • Does your function cope with 24hr time format?
  • Can you also output a list of times from an angle?  Ie. what times equate to 90 deg, 27 deg etc? 
    • If so can you output this as an array function so that a list can be shown in Excel?

Watch Accuracy Tracker


I had an idea the other day that I would write a small app in Excel to keep track of all my watches.

I was planning to use a constant source like :

http://time.is/

to keep track of the ‘real’ time and then have an ability to take a ‘snapshot’ of what the time is on each watch in a list ( that can be added to of course). This way using the inbuilt goodies of Excel all manner of graphs and stats can be applied to the raw data and people can see how their watch is behaving.

I was also thinking of adding a few features like resting orientation to see if any of the theories about leaving the watch 3 down, 9 down , dial up, dial down do influence the readings. Along with whether the chrono is running, is it being worn during the timing period etc.

Would anyone be interested in a copy of this? If anyone has any ideas / suggestions that would be great.

I am also thinking of using this as a quide too :

http://rcm-uk.amazon.co.uk/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=finraddev-21&o=2&p=8&l=as4&m=amazon&f=ifr&asins=B004BLIW22

Categories: Uncategorized

Essential tools for Excel VBA RAD (Rapid Application Development)

February 17, 2011 1 comment

I guess a major point of RAD is speed.  The clue is right there in the name: Rapid Application Development.

So, all other things being equal, how do we go about getting more speed.  I don’t mean smashing out a load of garbage or not testing things. :)

I mean what things can be used to help productivity?  I am going to list a few here.

I will keep adding to this list, but if anyone knows of any good sources please add a comment and I will add it in.

Battling with SQL.


I was having a ‘mare with SQL today and I stumbled across this :

http://blog.sqlauthority.com/2009/04/13/sql-server-introduction-to-joins-basic-of-joins/

I hope this helps people start to understand joins.

Categories: Beginner, SQL

Do you use protection? Really useful factoid – 002


We are all told that using protection is a good thing.  This applies to both real life and also programming, both in full OOP and the quasi OOP world of VBA / VB. It can be possible in some cases for your variables to be changed inside the sub / function you have called, even the ones one may have designated in your human mind as ‘input’ variables.   This can lead to odd behaviour and hard to find bugs.

So.. what am I going  on about?  Well I am talking about passing by value or by reference.  (Experienced VBA Programmers may want to skip this bit).   In VBA you can use two keywords ByRef or ByVal when defining your Sub or Function.   Read more…

Follow

Get every new post delivered to your Inbox.