Saturday, 27 December 2008

Excel Macro - Knitters Graph Paper

I wrote the following macro a while ago which produces Knitters Graph paper. I'm sure there are better things out there but this does do the job.

To try it do the following:

*update*
You can download it from here:
Gauge.xls
Just press the button. You'll still have to edit the code to change the gauge as described below:


1. In Excel open a new worksheet and goto the following menu option
Tools - Macro - Visual Basic Editor

2. On the LHS there should be a list of worksheets - double click on Sheet1

3. Chose CommandButton1 from the LHS drop down menu

4. If your gauge is different then you can play around with the following two numbers to match your values:
dStitchGauge
dRowGauge

If they are both set to 1 then the the cells will be square.

5. Save then go back to the worksheet and click on the button

5. That's it - you should get knitters graph paper produced on your worksheet like this (but remember to set the option to print the grid lines):







Here's the code:

Dim dRowGauge As Double
Dim dStitchGauge As Double
Dim dRatio As Double
Dim dColumnWidth As Double
Dim dRowHeight As Double

Const cSquareColumnWidth = 2
Const cSquareRowHeight = 15

dStitchGauge = 3 'Change this value to your stitch gauge
dRowGauge = 2 'Change this value to your row gauge

dRatio = dRowGauge / dStitchGauge

If dRatio <= 1 Then
dColumnWidth = dRatio * cSquareColumnWidth
dRowHeight = 1 * cSquareRowHeight
Else
dColumnWidth = 1 * cSquareColumnWidth
dRowHeight = (1 / dRatio) * cSquareRowHeight
End If

'Row Gauge to Column Gauge ratio
With Range("a1:iv65536")
.Clear
.RowHeight = dRowHeight
.ColumnWidth = dColumnWidth
End With

4 comments:

PrincessPea said...

That is very cool! I'm always playing around with charts and patterns, and have to try and visualise the stitches squashed into rectangles. Thanks for doing this.

Anonymous said...

I wasn't able to get this to work. I kept getting the following error:
"compile error: invalid outside procedure"
Also please advise if stitches /rows are for 4 inches or 1 inch? and if fractions are allowed?

HeyYeah said...

Hi - I've changed this so you can download the spreadsheet so it should be much easier.
It doesn't matter if it's for 4 inches or 1 inch as long as you use the same length for both stitch and row gauge. This is because it is the proportion that is important.
Fractions are fine (as long as you convert them to decimals of course).

t_britten said...

Dang!! Scribd won't let me download the file...I don't know why but it sure would be nice to have. Thanks for offering it!!

SassySean on Ravelry