i'm trying to learn Excel VBA for work and i did this guy's tutorial: http://www.vbtutor.net/VBA/vba_tutorial.html
i remember that there are a few of you who are good in Excel and many of you are programmers, so maybe you guys could recommend some practice problems i could do?
what i've done so far on my own is this kind of thing:
a greyscale pattern:
Code: Select all
Sub MyPattern1()
Sheet1.Cells.Clear
Dim iCounter As Integer
Dim rngRange As RANGE
Set rngRange = Sheet1.Cells
With rngRange
.Columns.ColumnWidth = .Columns("A").ColumnWidth / .Columns("A").Width * .Rows(1).Height
End With
Dim i As Long
Dim j As Long
For i = 1 To 36
For j = 1 To 36
If i > 12 And i <= 24 And j > 12 And j <= 24 Then
Cells(i, j).Interior.Color = RGB(i * (255 / 22) + j * (255 / 22) - (3315 / 11), i * (255 / 22) + j * (255 / 22) - (3315 / 11), i * (255 / 22) + j * (255 / 22) - (3315 / 11))
ElseIf i > 6 And i <= 30 And j > 6 And j <= 30 Then
Cells(i, j).Interior.Color = RGB(i * (-255 / 46) + j * (-255 / 46) + (7650 / 23), i * (-255 / 46) + j * (-255 / 46) + (7650 / 23), i * (-255 / 46) + j * (-255 / 46) + (7650 / 23))
'ElseIf i >= 1 And i <= 36 And j >= 1 And j <= 36 Then
Else: Cells(i, j).Interior.Color = RGB(i * (51 / 14) + j * (51 / 14) + (-51 / 7), i * (51 / 14) + j * (51 / 14) + (-51 / 7), i * (51 / 14) + j * (51 / 14) + (-51 / 7))
End If
Next j
Next i
End Sub
Code: Select all
Sub MyFib()
Sheet1.cells.Clear
cells(1, 3).NumberFormat = "0.0000000000000000000000000000000"
cells(2, 3).NumberFormat = "0.0000000000000000000000000000000"
Dim i As Integer
Dim vPhi As Variant
Dim vRemainder As Variant
cells(1, 1) = 1
cells(2, 1) = 1
Do
i = i + 1
cells(i + 2, 1) = cells(i + 1, 1) + cells(i, 1)
vRemainder = CDec(Abs(cells(i + 2, 1) / cells(i + 1, 1) - _
cells(i + 1, 1) / cells(i, 1)))
vPhi = CDec(cells(i + 2, 1) / cells(i + 1, 1))
Loop Until vRemainder < CDec(1E-16)
cells(1, 3) = vPhi
End Sub