View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default set range error in add sheet

You can not use Find to locate "". It won't work when done manually so for
the same reason it does not work via a macro. If you are looking for truely
blank cells (not formulas returning blank) then you could use xlDown and an
offest something like this

Range("A1").end(xlDown).offset(1,0).Select

or usually better come from the bottom up

cells(rows.count, "A").end(xlUp).offset(1,0).select

FYI when doing a Find you want to set it to a range object and then check
the range object to see if it is nothing. Also you really want to specify all
of the optional arguments of the find otherwise XL just uses whatever the
last settings where whci can cause a lot of grief.
--
HTH...

Jim Thomlinson


" wrote:

Hi All,
I am getting runtime error on below code,anyone can give a hand why
that happens?Thanks in advance.
Sub sukre()
Dim pn
Dim rng As Range
pn = ComboBox1.Value
bugun = Format(Date, "[$-409]d-mmm-yy;@")
If CheckBox1.Value = True Then
pn = OTB.Value
End If
Sheets.Add.Name = bugun
Set rng = Range("a1:a10000")
rng.Find("", rng(rng.Rows.Count)).Select ' HERE IS WHERE I AM
HAVING AN ERROR
Selection.Value = bugun
ActiveCell.Offset(0, 1).Value = pn
ActiveCell.Offset(0, 2).Value = PitUF.DTB.Value
ActiveCell.Offset(0, 3).Value = PitUF.RTB.Value
PitUF.ComboBox1 = ""
PitUF.OTB = ""
PitUF.DTB = ""
PitUF.RTB = ""
PitUF.ComboBox1.SetFocus
End Sub