Problem with code for setting a range

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,047
Would someone be so kind as to tell me what faux pas I have created in the following code please. It stops on the second to last line with a type mismatch. I am trying to set a range, so that I can copy it over from one workbook to another. Your help will be greatly appreciated

Sub Macro1()

Dim WBO As Workbook 'original workbook
Dim WBN As Workbook 'new workbook
Dim WSO As Worksheet 'original worksheet
Dim WSN As Worksheet 'new worksheet
Dim FinalRowHinter As Range
Dim StartRowHinter As Range


Set WBO = ActiveWorkbook

Set WSO = ActiveSheet

With WSO.Range("J1:J5000")

Set H = .Find("333 Count", LookIn:=xlValues)

End With

With WSO.Range("k1:k5000")

Set i = .Find(333, LookIn:=xlValues)

End With


FinalRowHinter = WSO.Cells(H, 11)
StartRowHinter = WSO.Cells(i, 1)
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I believe you've set H as a string "333 Count" when it's looking for an integer. Are you trying to look for the row location of the cell that contains "333 Count"?
 
Upvote 0
Yes thats right, when I added in a 'watch' it seems to correctly find the location of '333 Count' but yes I am trying to locate the row of where '333 count' is
 
Upvote 0
Try identifying your location of "333 Count" as a range (R in below example) and then setting H as the row of that range. You'll have to do the same for 333. Something like:

Dim R as Range
Dim H as Long

Set R = Cells.Find("333 Count", LookIn:=xlValues)
H = R.Row
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,319
Members
452,905
Latest member
deadwings

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