Problems with command button loop and blank cells

Cryoguy74

New Member
Joined
Sep 4, 2017
Messages
5
Good day all,

I had this working fine, Then I fixed a problem where my reports page retunred a lot of 01/01/1900 date lines that were not needed.
I fixed the formulas so that those cells would just be blank. And now my button doesn't work. It goes to the debugger and gives me this error

"runtime error 13
type missmatch"

this is the code its running
the debugger highlights the line in red


'set variables
Set datasheet = Sheet1
Set reportsheet = Sheet3




'clear old data
reportsheet.Range("A5:L100000").ClearContents




' TIME STAMP SHEET


reportsheet.Range("a5") = "THIS WEEK"


'next task






For i = 3 To datasheet.Cells(Rows.Count, 1).End(xlUp).Row

If datasheet.Cells(i, 1).Interior.ColorIndex <> 44 And _
datasheet.Cells(i, 1).Interior.ColorIndex <> 23 Then

If Year(datasheet.Cells(i, 8).Value) = Year(Date) And _
WorksheetFunction.WeekNum(datasheet.Cells(i, 8).Value, 2) = WorksheetFunction.WeekNum(Date, 2) Then

datasheet.Cells(i, 8).EntireRow.Copy
reportsheet.Range("a1000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End If
End If
Next i





reportsheet.Select






End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Re: I am almost finished! Problems with command button loop and blank cells

Suggest you check that the cell isn't blank:

Code:
'next task
For i = 3 To datasheet.Cells(Rows.Count, 1).End(xlUp).Row
    If datasheet.Cells(i, 1).Interior.ColorIndex <> 44 And _
    datasheet.Cells(i, 1).Interior.ColorIndex <> 23 And _
    datasheet.Cells(i, 8).Value <> "" Then
        If Year(datasheet.Cells(i, 8).Value) = Year(Date) And _
        WorksheetFunction.WeekNum(datasheet.Cells(i, 8).Value, 2) = WorksheetFunction.WeekNum(Date, 2) Then
            datasheet.Cells(i, 8).EntireRow.Copy
            reportsheet.Range("a1000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
            Application.CutCopyMode = False
        End If
    End If
Next i

WBD
 
Upvote 0
Re: I am almost finished! Problems with command button loop and blank cells

Awesome! Thanks so much I knew it had to be something simple. Works Great.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top