Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default My code fails


Hi,

I'm attemptng the following, to put mVal into any mCell in mSheet


Sub test(mSheet, mVal, mCell)
Dim wk As Workbook
Set wk = ActiveWorkbook
Dim sht As Worksheet
Set sht = wk.Worksheets(mSheet)

With sht
Range(mCell).Select
ActiveCell.Value = mVal
End With
Set sht = Nothing
Set wk = Nothing
End Sub



It doesn't work, but also doesn't report any errors.

It there anything obviously wrong with it?


Thanks - Kirk
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default My code fails

Sub test(mSheet, mVal, mCell)
ActiveWorkbook.Worksheets( _
mSheet).Range(mCell).Value = mVal
End Sub

--
Regards,
Tom Ogilvy


"kirkm" wrote:


Hi,

I'm attemptng the following, to put mVal into any mCell in mSheet


Sub test(mSheet, mVal, mCell)
Dim wk As Workbook
Set wk = ActiveWorkbook
Dim sht As Worksheet
Set sht = wk.Worksheets(mSheet)

With sht
Range(mCell).Select
ActiveCell.Value = mVal
End With
Set sht = Nothing
Set wk = Nothing
End Sub



It doesn't work, but also doesn't report any errors.

It there anything obviously wrong with it?


Thanks - Kirk

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default My code fails

Gary, just one '.' in
..Range(mCell).Value = mVal
right?

kirkm, this works just as well, although I realize you may have plans for
using this in a more generic form later:
Sub TestIt()
ActiveWorkook.Worksheets('Sheet1').Range("A1") = 10
End Sub

and looking at the long range view, this works for me also
Sub TestSetCellValue()
SetCellValue "Sheet1", "A1",44.92
End Sub
Sub SetCellValue(mSheet as string, mCell as string, mValue as Variant)
'mValue may be text, number or even null as a Variant
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets(mSheet)
With wks
.Range(mCell) = mValue
End With
Set wks = Nothing
End Sub


"Gary Keramidas" wrote:

this works for me, but you should dim the variables: mcell, msheet, mval:

Sub test()
Dim wk As Workbook
Set wk = ActiveWorkbook
mSheet = "Sheet1"
mCell = "A1"
mVal = 10
Dim sht As Worksheet
Set sht = wk.Worksheets(mSheet)

With sht
..Range(mCell).Value = mVal
End With
Set sht = Nothing
Set wk = Nothing
End Sub

--


Gary


"kirkm" wrote in message
...

Hi,

I'm attemptng the following, to put mVal into any mCell in mSheet


Sub test(mSheet, mVal, mCell)
Dim wk As Workbook
Set wk = ActiveWorkbook
Dim sht As Worksheet
Set sht = wk.Worksheets(mSheet)

With sht
Range(mCell).Select
ActiveCell.Value = mVal
End With
Set sht = Nothing
Set wk = Nothing
End Sub



It doesn't work, but also doesn't report any errors.

It there anything obviously wrong with it?


Thanks - Kirk




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default My code fails

On Wed, 21 Feb 2007 21:29:06 +1300, kirkm
wrote:


Thank you very much, one and all.

Sorted and working perfectly.

Cheers - Kirk
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code fails when sheet is protected Tail Wind Excel Discussion (Misc queries) 3 September 4th 07 03:23 PM
Copy paste code fails Ron Dean[_2_] Excel Programming 0 January 17th 06 11:49 AM
Code fails if ran more than once Christy Excel Programming 11 August 31st 05 06:57 PM
Named Range Fails in VBA Code Dean Hinson[_3_] Excel Programming 3 January 24th 05 03:48 PM
Logitech's newest mouse scroll fails in VBE code pane Robin Hammond Excel Programming 0 July 11th 03 02:29 PM


All times are GMT +1. The time now is 08:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"