Error Message on a code

carlleese24

Board Regular
Joined
Mar 15, 2005
Messages
108
Hi

I have a code here that basically searches a value and puts a figure in the next few cells

Code:
For Each Name In Worksheets("rota").Range(.Cells(1, Sheets("Swipe_Data").Range("b16").Value), .Cells(1000, Sheets("Swipe_Data").Range("b16").Value)).SpecialCells(xlCellTypeConstants, 1)
With ActiveCell.Offset(0, 1)
Set c = .Find(Name.Value, LookIn:=xlValues)
If Not c Is Nothing Then
Name.Offset(0, Sheets("Swipe_Data").Range("a16")).Value = c.Offset(0, 4).Value
End If
End With
Next Name

The error message points to this bit of the code .cells and says
compile error:
invalid or unqualified reference


Any help on this would appreciated
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try taking the dot qualifier off (.Cells-->Cells). You don't need it as you're already in an explicit reference to the sheet. You'd need it if you were in a With statement. Unless you're trying to also refer to the Swipe_Data sheet.

HTH,
 
Upvote 0
Hi Smitty

I removed the 2 dots on the cells now it looks like this

Code:
For Each Name In Worksheets("rota").Range(Cells(1, Sheets("Swipe_Data").Range("b16").Value), Cells(1000, Sheets("Swipe_Data").Range("b16").Value)).SpecialCells(xlCellTypeConstants, 1)
With ActiveCell.Offset(0, 1)
Set c = .Find(Name.Value, LookIn:=xlValues)
If Not c Is Nothing Then
Name.Offset(0, Sheets("Swipe_Data").Range("a16")).Value = c.Offset(0, 4).Value
End If
End With
Next Name



Now it gives me this error
run time error 1004

application defined or object defined error


it highlights this code in yellow

Code:
For Each Name In Worksheets("rota").Range(Cells(1, Sheets("Swipe_Data").Range("b16").Value), Cells(1000, Sheets("Swipe_Data").Range("b16").Value)).SpecialCells(xlCellTypeConstants, 1)
 
Upvote 0
OK,

I didn't see the rest of the code line the first time around.

So you're trying to work on Row 1 in the rota sheet to Row 1000, with the value in the Swipe_Data sheet as the column reference?
 
Upvote 0
one of the values in the cells is empty or incorrect, check b16 in swipe data
also maybe you need to qualify the cells with the sheet reference
 
Upvote 0
Hi Smitty


Yes that is correct

I have just solved it I think

Code:
For Each Name In Worksheets("rota").Range(Sheets("rota").Cells(1, Sheets("Swipe_Data").Range("b16").Value), Sheets("rota").Cells(1000, Sheets("Swipe_Data").Range("b16").Value)).SpecialCells(xlCellTypeConstants, 1)
With ActiveCell.Offset(0, 1)
Set c = .Find(Name.Value, LookIn:=xlValues)
If Not c Is Nothing Then
Name.Offset(0, Sheets("Swipe_Data").Range("a16")).Value = c.Offset(0, 4).Value
End If
End With
Next Name

there is no errors now and it seems to be working fine
 
Upvote 0
Glad you got it sorted out.

That's one of those cases where it's often hard for someone to try to test a blank solution, but a lot of times when you work at it a bit you get there.
 
Upvote 0

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

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