Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

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