What's wrong with my macro code?

A

Anders M

This problem occours on Office 2007 (with updates) as well as Office
2010 (with (and without) updates).

I have a spredsheet containing multiple sheets. When running the macro I
want to copy two matrices from sheet 1 ("Scorekort") to sheet 2
("Statistik") where the values are added to existing matrices.

Previously, this was running smoothly. However, since Office 2007 was
updated with various updates and now the arrival of Office 2010 the
macro doesn't work anymore. It simply screws up the 2 existing matrices
on sheet 2 ("Statistik"), which now holds entries refering to extreme
values.

Eg. instead of holding the entry 31 in cell AB6 it now refers to
=30+(COUNTIF(#REFERENCE!;4)) - it should have added 1 to 30.

Other cells contain:
=65+(COUNTIF(AD1048552:AD1048573;6)) - notice the extreme cell numbers!

Can anybody help me out here.

The macro also adds the values from Sheet 1 ("Scorekort") til Sheet 4
("Database"), and it copies a value from one cell to another on sheet 1
- these to things, however, works like a charm!

Here is the macro:

Sub Gem_scorekort()
'
' Gem_scorekort Macro
'
Dim destrange As Range
Dim smallrng As Range
Application.ScreenUpdating = False
For Each smallrng In Sheets("Scorekort"). _
Range("L3:L35").Areas
Set destrange = Sheets("Database").Range("A" & _
LastRow(Sheets("Database")) + 1)
smallrng.Copy
destrange.PasteSpecial xlPasteValues, , False, True
Application.CutCopyMode = False
Next smallrng
'
' Opdater statistik
'
Sheets("Scorekort").Range("M39:O48").Copy
Sheets("Statistik").Range("AB3").PasteSpecial Operation:=xlAdd
Sheets("Scorekort").Range("P38:R48").Copy
Sheets("Statistik").Range("AG3").PasteSpecial Operation:=xlAdd
'
' Opdater handicap
'
Sheets("Scorekort").Range("B39").Copy
Sheets("Scorekort").Range("B8").PasteSpecial xlPasteValues
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function



What am I missing?

Regards,
Anders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top