1

I am totally new to VBA. I use it maybe once a year and when I do I search this and other forums for code. For my humble needs, that usually works perfectly. Unfortunately due to my lack of real understanding of the code, in this case I am unable to see what I`m doing wrong. So hopefully somebody can help.

I have a timesheet where I want to copy the values to a datasheet. I have that working. But it is important that the users fill-out the right weeknumber in the form. In order to check if they have done that, I have written a piece of code that should return a messagebox when the weeknumber is not filled. When I simply use a reference to a single cell the code works. But as the weeknumber is not filled in in the same cell on all forms I want the macro to search for the text "Weeknumber: " and then check if the cell next to it is empty or not.

Sub Weeknumber()
dim cl as Range
Worksheets("Invul_Tabel").Activate
With Worksheets("Invul_Tabel").Cells
Set cl = .Find("Weeknummer:", After:=.Range("A1"), LookIn:=xlValues)
If IsEmpty(Range(cl).Offset(0, 1).Value) = True Then
  MsgBox "Geen weeknummer ingevuld"
  Exit Sub
     End If
End With

End Sub

The code gives an error on the "If IsEmpty" line" (error 1004). Is probably simple, but i can`t seem to figure it out!

Zeno
  • 13
  • 3

1 Answers1

3

Your cl variable is already a range.

Change

If IsEmpty(Range(cl).Offset(0, 1).Value) = True Then

to

If IsEmpty(cl.Offset(0, 1).Value) Then
Excelosaurus
  • 2,789
  • 1
  • 14
  • 20