Runtime error 13-- Setting a variant Range?!

  • Thread starter Thread starter michelle.harshberger
  • Start date Start date
M

michelle.harshberger

Why doesn't this work?



Dim MyRange as Variant

Set MyRange = ("C" &(Me.txtItem_Number.Value) & ":G"
&((Me.txtItem_Number.Value)+ 2))

Range(MyRange).ClearContents




I also tried Dim MyRange as Range. How can I work around this when I
need to clear a different area every time the macro runs?
 
ANSWERED MY OWN QUESTION:

Dim MyRange as Variant
MyRange = ("C" &(Me.txtItem_Number.Value) & ":G"
&((Me.txtItem_Number.Value)+ 2))

Range(MyRange).Clear Contents

That Set thing always gets me! erg!

:)
 
Try something like this...

Dim MyRange as Range

with Me.txtItem_Number
Set MyRange = Activesheet.Range("C" & .Value & ":G" & .Value + 2)
end with
MyRange.ClearContents
 
Dim MyRange As String

MyRange = ("C" & (Me.txtItem_Number.Value) & ":G" &
((Me.txtItem_Number.Value) + 2))

Range(MyRange).ClearContents


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top