Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Help with Run-time error: "Type Mismatch"

Hallo,
I have made the next macro, but when I want to run it I get an error
message: "Run-time error 13: Type mimatch". Can anybody please tell me what
I'm doing wrong.

Sub Abs_Bkg()

Dim rng As Range
Dim lRownum As Long
Dim i As Long
Dim j As Long
Dim exSh As Worksheet
Dim wks As Worksheet
Set exSh = Worksheets("raw data from spad it")
Set wks = Worksheets("Calculated Data")

With exSh.UsedRange
lRownum = .Cells(.Rows.Count, 1).Row
End With
With wks
For j = 1 To 4
Set rng = Range("O2:O" & lRownum)
For i = 2 To lRownum
wks.Cells(i, rng.Offset(V, j)).Value = exSh.Cells(i, rng.Offset(O,
j)).Value - _
wks.Cells(rng.Offset("AL4", j)).Value
Next i
j = j + 1
Next
End With

End Sub

What this macro has to do is to substract AL4 (worksheet "wks") from O2
(worksheet "exSh") and put the solution in V2 ("wks"). And then go to the
next row but keep "AL4" absolute. Do the same calculation till the lastrow.
Then go to the next column, now is AL4 variable. So; P2 - AM4 = W2. When
going to the next row AM4 stays AM4.

Thanks,
-Metin-
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 339
Default Help with Run-time error: "Type Mismatch"


"Metin" wrote in message
...
Hallo,
I have made the next macro, but when I want to run it I get an error
message: "Run-time error 13: Type mimatch". Can anybody please tell me

what
I'm doing wrong.

Sub Abs_Bkg()

Dim rng As Range
Dim lRownum As Long
Dim i As Long
Dim j As Long
Dim exSh As Worksheet
Dim wks As Worksheet
Set exSh = Worksheets("raw data from spad it")
Set wks = Worksheets("Calculated Data")

With exSh.UsedRange
lRownum = .Cells(.Rows.Count, 1).Row
End With
With wks
For j = 1 To 4
Set rng = Range("O2:O" & lRownum)
For i = 2 To lRownum
wks.Cells(i, rng.Offset(V, j)).Value = exSh.Cells(i, rng.Offset(O,
j)).Value - _
wks.Cells(rng.Offset("AL4",

j)).Value
Next i
j = j + 1
Next
End With

End Sub

What this macro has to do is to substract AL4 (worksheet "wks") from O2
(worksheet "exSh") and put the solution in V2 ("wks"). And then go to the
next row but keep "AL4" absolute. Do the same calculation till the

lastrow.
Then go to the next column, now is AL4 variable. So; P2 - AM4 = W2. When
going to the next row AM4 stays AM4.

Thanks,
-Metin-


I think your macro attempts to subtract a number from text or similar. You
don't check if "wks.Cells(rng.Offset("AL4", j)).Value"
or "exSh.Cells(i, rng.Offset(O, j)).Value" is really a numeric value. Check
how many loops it does before there's an error.

/Fredrik

/Fredrik


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Help with Run-time error: "Type Mismatch"

Metin,

Offset requires a number, not a string:

Offset("AL4", j)).Value won't work.

And there is no need to loop through. You can put formulas into all the
needed cells with one line: you can also convert them to values if you no
longer want formulas, also with a single line. See the example below.

HTH,
Bernie
MS Excel MVP

Sub Abs_Bkg2()

Dim rng As Range 'not needed
Dim lRownum As Long
Dim i As Long 'not needed
Dim j As Long 'not needed
Dim exSh As Worksheet 'not really needed, but OK
Dim wks As Worksheet 'not really needed, but OK
Set exSh = Worksheets("raw data from spad it")
Set wks = Worksheets("Calculated Data")

lRownum = exSh.Range("A1").SpecialCells(xlCellTypeLastCell). Row

With wks.Range("V2:Y" & lRownum)
.FormulaR1C1 = _
"='raw data from spad it'!RC[-7]-'Calculated Data'!R4C[16]"
'This next line is optional
' Use it to remove the formulas but leave values
.Value = .Value
End With
End Sub




"Metin" wrote in message
...
Hallo,
I have made the next macro, but when I want to run it I get an error
message: "Run-time error 13: Type mimatch". Can anybody please tell me

what
I'm doing wrong.

Sub Abs_Bkg()

Dim rng As Range
Dim lRownum As Long
Dim i As Long
Dim j As Long
Dim exSh As Worksheet
Dim wks As Worksheet
Set exSh = Worksheets("raw data from spad it")
Set wks = Worksheets("Calculated Data")

With exSh.UsedRange
lRownum = .Cells(.Rows.Count, 1).Row
End With
With wks
For j = 1 To 4
Set rng = Range("O2:O" & lRownum)
For i = 2 To lRownum
wks.Cells(i, rng.Offset(V, j)).Value = exSh.Cells(i, rng.Offset(O,
j)).Value - _
wks.Cells(rng.Offset("AL4",

j)).Value
Next i
j = j + 1
Next
End With

End Sub

What this macro has to do is to substract AL4 (worksheet "wks") from O2
(worksheet "exSh") and put the solution in V2 ("wks"). And then go to the
next row but keep "AL4" absolute. Do the same calculation till the

lastrow.
Then go to the next column, now is AL4 variable. So; P2 - AM4 = W2. When
going to the next row AM4 stays AM4.

Thanks,
-Metin-



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Type mismatch" when I try to fill an Array variable with "+" [email protected] Excel Discussion (Misc queries) 1 April 17th 07 01:28 PM
multiple file uploading - runtime error'13': type mismatch "While Counter <= UBound(FName)" Sinner Excel Discussion (Misc queries) 3 March 1st 07 09:44 AM
"FIND" generates "Type mismatch" error quartz[_2_] Excel Programming 5 November 16th 04 03:29 PM
Type mismatch: .Cells(i).Value = "=rc[-1]" / vl Kobayashi[_3_] Excel Programming 7 September 26th 03 11:35 AM
Copying data to another worksheet gives "Type Mismatch" error TB[_3_] Excel Programming 6 July 28th 03 12:44 PM


All times are GMT +1. The time now is 07:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"