Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default mismatch error

I am currently trying to look at C18:C20 and compare that to C22:C24.
And if they are the same then do C18+C22, C19+C23 and C20+C24. But it
keeps erroring saying mismatch. I've tried to reduce the range(to only
2 rows as shown in the code below) but the only time it will work is
if I just do one cell at a time but I need the macro to look at the
group.

Sub test()
Dim rang1 As Range
Dim rang2 As Range

Set rang1 = Range(Cells(18, 3), Cells(19, 3))
Set rang2 = Range(Cells(22, 3), Cells(23, 3))
If rang1 = rang2 Then Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))
If rang1 = rang2 Then Cells(19, 7) = (Cells(19, 7) + Cells(23, 7))
If rang1 = rang2 Then Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default mismatch error

Untested. Try this.

Sub test()
Dim rang1 As Range
Dim rang2 As Range

Set rang1 = Range("C18:C20")
Set rang2 = Range("C22:C24")
If rang1.value = rang2.value Then
Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))
Cells(19, 7) = (Cells(19, 7) + Cells(23, 7))
Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
end if
End
End Sub


" wrote:

I am currently trying to look at C18:C20 and compare that to C22:C24.
And if they are the same then do C18+C22, C19+C23 and C20+C24. But it
keeps erroring saying mismatch. I've tried to reduce the range(to only
2 rows as shown in the code below) but the only time it will work is
if I just do one cell at a time but I need the macro to look at the
group.

Sub test()
Dim rang1 As Range
Dim rang2 As Range

Set rang1 = Range(Cells(18, 3), Cells(19, 3))
Set rang2 = Range(Cells(22, 3), Cells(23, 3))
If rang1 = rang2 Then Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))
If rang1 = rang2 Then Cells(19, 7) = (Cells(19, 7) + Cells(23, 7))
If rang1 = rang2 Then Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default mismatch error

Ignore my previous response.

Sub test()
Dim rang1 As Range
Dim rang2 As Range

Set rang1 = Range("C18:C20")
Set rang2 = Range("C22:C24")
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(18, 7) = Cells(18, 7) + Cells(22, 7)
Cells(19, 7) = Cells(19, 7) + Cells(23, 7)
Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End If
End Sub


" wrote:

I am currently trying to look at C18:C20 and compare that to C22:C24.
And if they are the same then do C18+C22, C19+C23 and C20+C24. But it
keeps erroring saying mismatch. I've tried to reduce the range(to only
2 rows as shown in the code below) but the only time it will work is
if I just do one cell at a time but I need the macro to look at the
group.

Sub test()
Dim rang1 As Range
Dim rang2 As Range

Set rang1 = Range(Cells(18, 3), Cells(19, 3))
Set rang2 = Range(Cells(22, 3), Cells(23, 3))
If rang1 = rang2 Then Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))
If rang1 = rang2 Then Cells(19, 7) = (Cells(19, 7) + Cells(23, 7))
If rang1 = rang2 Then Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default mismatch error

On Jul 23, 4:14 pm, Barb Reinhardt
wrote:
Ignore my previous response.

Sub test()
Dim rang1 As Range
Dim rang2 As Range

Set rang1 = Range("C18:C20")
Set rang2 = Range("C22:C24")
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(18, 7) = Cells(18, 7) + Cells(22, 7)
Cells(19, 7) = Cells(19, 7) + Cells(23, 7)
Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End If
End Sub



" wrote:
I am currently trying to look at C18:C20 and compare that to C22:C24.
And if they are the same then do C18+C22, C19+C23 and C20+C24. But it
keeps erroring saying mismatch. I've tried to reduce the range(to only
2 rows as shown in the code below) but the only time it will work is
if I just do one cell at a time but I need the macro to look at the
group.


Sub test()
Dim rang1 As Range
Dim rang2 As Range


Set rang1 = Range(Cells(18, 3), Cells(19, 3))
Set rang2 = Range(Cells(22, 3), Cells(23, 3))
If rang1 = rang2 Then Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))
If rang1 = rang2 Then Cells(19, 7) = (Cells(19, 7) + Cells(23, 7))
If rang1 = rang2 Then Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End
End Sub- Hide quoted text -


- Show quoted text -


So Thank you very much it did work. However, usually after I get the
basic code I can create the loop with no problem but I'm having
difficulty this time. This is what I have so far.

Sub testt()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
For m = 0 To 60 Step 4
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(2 + m, 7) = Cells(2 + m, 7) + Cells(6 + m, 7)
Cells(3 + m, 7) = Cells(3 + m, 7) + Cells(7 + m, 7)
Cells(4 + m, 7) = Cells(4 + m, 7) + Cells(8 + m, 7)

End If
Next
End Sub

I also want the column part to be looping also but I can't get the row
part. What happens is sometimes they add sometime they don't but I
haven't figured out why some do and some don't.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default mismatch error

Try this

Sub testt()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
Dim lRow As Long
Dim lCol As Long

For lCol = 7 To 7
For m = 0 To 60 Step 4
'Not sure what you want to do with columns in ranges
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
For lRow = 2 To 4
'Changed 7 to lCol
Cells(lRow + m, lCol) = Cells(lRow + m, lCol) + Cells(lRow +
4 + m, lCol)
Next lRow
End If
Next
Next lCol
End Sub


" wrote:

On Jul 23, 4:14 pm, Barb Reinhardt
wrote:
Ignore my previous response.

Sub test()
Dim rang1 As Range
Dim rang2 As Range

Set rang1 = Range("C18:C20")
Set rang2 = Range("C22:C24")
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(18, 7) = Cells(18, 7) + Cells(22, 7)
Cells(19, 7) = Cells(19, 7) + Cells(23, 7)
Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End If
End Sub



" wrote:
I am currently trying to look at C18:C20 and compare that to C22:C24.
And if they are the same then do C18+C22, C19+C23 and C20+C24. But it
keeps erroring saying mismatch. I've tried to reduce the range(to only
2 rows as shown in the code below) but the only time it will work is
if I just do one cell at a time but I need the macro to look at the
group.


Sub test()
Dim rang1 As Range
Dim rang2 As Range


Set rang1 = Range(Cells(18, 3), Cells(19, 3))
Set rang2 = Range(Cells(22, 3), Cells(23, 3))
If rang1 = rang2 Then Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))
If rang1 = rang2 Then Cells(19, 7) = (Cells(19, 7) + Cells(23, 7))
If rang1 = rang2 Then Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End
End Sub- Hide quoted text -


- Show quoted text -


So Thank you very much it did work. However, usually after I get the
basic code I can create the loop with no problem but I'm having
difficulty this time. This is what I have so far.

Sub testt()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
For m = 0 To 60 Step 4
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(2 + m, 7) = Cells(2 + m, 7) + Cells(6 + m, 7)
Cells(3 + m, 7) = Cells(3 + m, 7) + Cells(7 + m, 7)
Cells(4 + m, 7) = Cells(4 + m, 7) + Cells(8 + m, 7)

End If
Next
End Sub

I also want the column part to be looping also but I can't get the row
part. What happens is sometimes they add sometime they don't but I
haven't figured out why some do and some don't.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default mismatch error

On Jul 24, 9:16 am, Barb Reinhardt
wrote:
Try this

Sub testt()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
Dim lRow As Long
Dim lCol As Long

For lCol = 7 To 7
For m = 0 To 60 Step 4
'Not sure what you want to do with columns in ranges
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
For lRow = 2 To 4
'Changed 7 to lCol
Cells(lRow + m, lCol) = Cells(lRow + m, lCol) + Cells(lRow +
4 + m, lCol)
Next lRow
End If
Next
Next lCol
End Sub



" wrote:
On Jul 23, 4:14 pm, Barb Reinhardt
wrote:
Ignore my previous response.


Sub test()
Dim rang1 As Range
Dim rang2 As Range


Set rang1 = Range("C18:C20")
Set rang2 = Range("C22:C24")
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(18, 7) = Cells(18, 7) + Cells(22, 7)
Cells(19, 7) = Cells(19, 7) + Cells(23, 7)
Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End If
End Sub


" wrote:
I am currently trying to look at C18:C20 and compare that to C22:C24.
And if they are the same then do C18+C22, C19+C23 and C20+C24. But it
keeps erroring saying mismatch. I've tried to reduce the range(to only
2 rows as shown in the code below) but the only time it will work is
if I just do one cell at a time but I need the macro to look at the
group.


Sub test()
Dim rang1 As Range
Dim rang2 As Range


Set rang1 = Range(Cells(18, 3), Cells(19, 3))
Set rang2 = Range(Cells(22, 3), Cells(23, 3))
If rang1 = rang2 Then Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))
If rang1 = rang2 Then Cells(19, 7) = (Cells(19, 7) + Cells(23, 7))
If rang1 = rang2 Then Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End
End Sub- Hide quoted text -


- Show quoted text -


So Thank you very much it did work. However, usually after I get the
basic code I can create the loop with no problem but I'm having
difficulty this time. This is what I have so far.


Sub testt()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
For m = 0 To 60 Step 4
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(2 + m, 7) = Cells(2 + m, 7) + Cells(6 + m, 7)
Cells(3 + m, 7) = Cells(3 + m, 7) + Cells(7 + m, 7)
Cells(4 + m, 7) = Cells(4 + m, 7) + Cells(8 + m, 7)


End If
Next
End Sub


I also want the column part to be looping also but I can't get the row
part. What happens is sometimes they add sometime they don't but I
haven't figured out why some do and some don't.- Hide quoted text -


- Show quoted text -


Sub testft()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
Dim lRow As Long
Dim lCol As Long


For lCol = 7 To 70 Step 7
For m = 0 To 60 Step 4
'Not sure what you want to do with columns in ranges
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2)
Then
For lRow = 2 To 4
'Changed 7 to lCol
Cells(lRow + m, lCol) = Cells(lRow + m, lCol) +
Cells(lRow + 4 + m, lCol)
Next lRow
End If
Next
Next lCol
End Sub
this is with what I want with the columns but it still does the same
thing. Basically acts as if the condition part (rang1=rang2) is not
even there.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default mismatch error

Look at your range definitions. You never change the columns in them.

FYI, the convention for most posters in this newsgroup is to top post. The
thread gets very confusing when some top post and some bottom post.



" wrote:

On Jul 24, 9:16 am, Barb Reinhardt
wrote:
Try this

Sub testt()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
Dim lRow As Long
Dim lCol As Long

For lCol = 7 To 7
For m = 0 To 60 Step 4
'Not sure what you want to do with columns in ranges
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
For lRow = 2 To 4
'Changed 7 to lCol
Cells(lRow + m, lCol) = Cells(lRow + m, lCol) + Cells(lRow +
4 + m, lCol)
Next lRow
End If
Next
Next lCol
End Sub



" wrote:
On Jul 23, 4:14 pm, Barb Reinhardt
wrote:
Ignore my previous response.


Sub test()
Dim rang1 As Range
Dim rang2 As Range


Set rang1 = Range("C18:C20")
Set rang2 = Range("C22:C24")
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(18, 7) = Cells(18, 7) + Cells(22, 7)
Cells(19, 7) = Cells(19, 7) + Cells(23, 7)
Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End If
End Sub


" wrote:
I am currently trying to look at C18:C20 and compare that to C22:C24.
And if they are the same then do C18+C22, C19+C23 and C20+C24. But it
keeps erroring saying mismatch. I've tried to reduce the range(to only
2 rows as shown in the code below) but the only time it will work is
if I just do one cell at a time but I need the macro to look at the
group.


Sub test()
Dim rang1 As Range
Dim rang2 As Range


Set rang1 = Range(Cells(18, 3), Cells(19, 3))
Set rang2 = Range(Cells(22, 3), Cells(23, 3))
If rang1 = rang2 Then Cells(18, 7) = (Cells(18, 7) + Cells(22, 7))
If rang1 = rang2 Then Cells(19, 7) = (Cells(19, 7) + Cells(23, 7))
If rang1 = rang2 Then Cells(20, 7) = Cells(20, 7) + Cells(24, 7)
End
End Sub- Hide quoted text -


- Show quoted text -


So Thank you very much it did work. However, usually after I get the
basic code I can create the loop with no problem but I'm having
difficulty this time. This is what I have so far.


Sub testt()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
For m = 0 To 60 Step 4
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2) Then
Cells(2 + m, 7) = Cells(2 + m, 7) + Cells(6 + m, 7)
Cells(3 + m, 7) = Cells(3 + m, 7) + Cells(7 + m, 7)
Cells(4 + m, 7) = Cells(4 + m, 7) + Cells(8 + m, 7)


End If
Next
End Sub


I also want the column part to be looping also but I can't get the row
part. What happens is sometimes they add sometime they don't but I
haven't figured out why some do and some don't.- Hide quoted text -


- Show quoted text -


Sub testft()
Dim rang1 As Range
Dim rang2 As Range
Dim m As Integer
Dim lRow As Long
Dim lCol As Long


For lCol = 7 To 70 Step 7
For m = 0 To 60 Step 4
'Not sure what you want to do with columns in ranges
Set rang1 = Range(Cells(2 + m, 3), Cells(4 + m, 4))
Set rang2 = Range(Cells(6 + m, 3), Cells(8 + m, 4))
If WorksheetFunction.Sum(rang1) = WorksheetFunction.Sum(rang2)
Then
For lRow = 2 To 4
'Changed 7 to lCol
Cells(lRow + m, lCol) = Cells(lRow + m, lCol) +
Cells(lRow + 4 + m, lCol)
Next lRow
End If
Next
Next lCol
End Sub
this is with what I want with the columns but it still does the same
thing. Basically acts as if the condition part (rang1=rang2) is not
even there.


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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
xpath error? Runtime Error 13 type mismatch Steve M[_2_] Excel Discussion (Misc queries) 0 January 17th 08 01:16 AM
Conditional Formatting - Run Time Error '13' Type Mismatch Error ksp Excel Programming 0 July 11th 06 07:06 AM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM


All times are GMT +1. The time now is 01:11 AM.

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

About Us

"It's about Microsoft Excel"