Why am I getting a mismatch Error

bigck2

Board Regular
Joined
Feb 20, 2014
Messages
146
Hello,

I keep getting a mismatch error, but i can't figure out why. Here is the code:

Sub Report()


Dim LR As Long
Dim LC As Long
Dim Rooms As Long
Dim ADR As Long
Dim Nights As Long
Dim r As Long
Dim c As Long

LR = Cells(Rows.Count, 1).End(xlUp).Row
LC = Cells(16, Columns.Count).End(xlToRight).Column

For r = 18 To LR
For c = 17 To LC
If Cells(r, c).Value = "Here" Then
Rooms = Cells(r, 14).Value
ADR = Cells(r, 16).Value
Nights = Cells(r, 12).Value

Range(Cells(r, c), Cells(r, (c + Nights))).Value = Rooms * ADR
End If
Next c
Next r


End Sub


When I try to run I get Run-time error '13': Type mismatch.

If I click debug, it highlights the row: If Cells(r,c).Value = "Here" Then


I have also tried using: If Cells(r,c).Value = 1 Then

And changed the formula in my worksheet to supply '1' instead of 'Here'.

I can't figure this out. It makes sense to me.

Thanks for any help.

Chris
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Ragnar1211

Well-known Member
Joined
Jul 10, 2008
Messages
571
Well not sure if this is part of the issue, but shouldn't this:
LC = Cells(16, Columns.Count).End(xlToRight).Column

be this instead:
LC = Cells(16, Columns.Count).End(xlToLeft).Column
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,276
Office Version
  1. 2013
Platform
  1. Windows
Also, LC and C should be declared as Integer, not Long
 

bigck2

Board Regular
Joined
Feb 20, 2014
Messages
146
Hey guys,

Thanks for the input.

Ragnar1211, you were definitely correct about my LC variable.

rintaro, you're suggestion worked. However, I think I was trying to loop through way to many cells. I ended up changing my code to:

Sub Report()


Dim LR As Long
Dim LC As Long
Dim Rooms As Long
Dim ADR As Long
Dim Nights As Long
Dim r As Long
Dim c As Long
Dim RealDates As Range

LR = Cells(Rows.Count, 1).End(xlUp).Row
LC = Cells(16, Columns.Count).End(xlToRight).Column


Range("Q17").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.SpecialCells(xlCellTypeFormulas, 7).Select

Set RealDates = Selection

For Each Cell In RealDates
r = Cell.Row
c = Cell.Column
Rooms = Cells(r, 14).Value
ADR = Cells(r, 16).Value
Nights = Cells(r, 12).Value

Range(Cells(r, c), Cells(r, (c + Nights - 1))).Value = Rooms * ADR
Next Cell




End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,445
Messages
5,528,801
Members
409,835
Latest member
Mafu1267

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top