Method Range of Object Worksheet Failed

hmk

Active Member
Joined
Jun 8, 2004
Messages
423
hi there
when excution get to this level
Code:
With ws
    .Range(r & Exp).Value = tot.Value
    .Cells(r & Exp) = tot.Value
 End With
then it gives me Method Range of Object Worksheet Failed
any idea why ?

The whole code is :

Code:
Private Sub cmdAdd_Click()
    Dim r As Long, Exp As Long
    Dim ws As Worksheet
    Set ws = Worksheets("sheet2")

r = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

'Exp Name
Exp = ThisWorkbook.Sheets(2).Cells.Find(what:=ComboBox1.Value, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns,  _SearchDirection:=xlNext).Column

With ws
    .Range(r & Exp).Value = tot.Value
    .Cells(r & Exp) = tot.Value
 End With

DocNo.Value = ""
ComboBox1.Value = ""
tot.Value = ""

Unload Me

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Is the Find actually finding anything?

Have you tried stepping through the code with F8 to check?
 
Upvote 0
yes the Find does find what it should find.

yes i tried with F8 many times
 
Upvote 0
Hi, helmekki,

simply look to the syntax

Range("A1")
Cells(1, 1)

r is a number (row)
Exp is a number (column)
let's assume r = 100 and Exp = 10

Range(10010) doesn't exist
Cells(10010) neigther
you need .Cells(r, Exp)
which is Cells(100, 10)

kind regards,
Erik
 
Upvote 0
erik.van.geit, Norie Thank u very much

I got my mistake throgh your help (y)
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,484
Members
448,967
Latest member
visheshkotha

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