Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
BRC BRC is offline
external usenet poster
 
Posts: 10
Default How to use variable in code

sub filldata

dim cap as long
' for purpose this of illustration F16= .15
cap = Sheet4.Range("f16").Value
' to verify that cap is initialized
Msgbox(cap)
' for purpose of illustration c6=.20
Range("d6").Formula = "=IF(c6<0,0,IF(c6cap,cap,c6))"
end sub

If I replace "cap" with a number ( .15) it works fine but when I try to
use the variable cap I get a #name? error in the cells.
I believe I may not using correct punctuation around the variable. Any
suggestions Thanks
BRC

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to use variable in code

you can try this

Range("d6").Formula = "=IF(c6<0,0,IF(c6" & cap & "," & cap & ",c6))"


--


Gary


"BRC" wrote in message
ups.com...
sub filldata

dim cap as long
' for purpose this of illustration F16= .15
cap = Sheet4.Range("f16").Value
' to verify that cap is initialized
Msgbox(cap)
' for purpose of illustration c6=.20
Range("d6").Formula = "=IF(c6<0,0,IF(c6cap,cap,c6))"
end sub

If I replace "cap" with a number ( .15) it works fine but when I try to
use the variable cap I get a #name? error in the cells.
I believe I may not using correct punctuation around the variable. Any
suggestions Thanks
BRC



  #3   Report Post  
Posted to microsoft.public.excel.programming
BRC BRC is offline
external usenet poster
 
Posts: 10
Default How to use variable in code

Sorry about that, I had removed the "long" from the dim statement. I
just had "dim cap " which I believe initializes a varient. Should I be
using something else there? Thanks
BRC
JMay wrote:
Dim cap as Long <<< means cap is a long INTEGER!! (no decimals) RIGht?
HTH

"BRC" wrote:

sub filldata

dim cap as long
' for purpose this of illustration F16= .15
cap = Sheet4.Range("f16").Value
' to verify that cap is initialized
Msgbox(cap)
' for purpose of illustration c6=.20
Range("d6").Formula = "=IF(c6<0,0,IF(c6cap,cap,c6))"
end sub

If I replace "cap" with a number ( .15) it works fine but when I try to
use the variable cap I get a #name? error in the cells.
I believe I may not using correct punctuation around the variable. Any
suggestions Thanks
BRC



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default How to use variable in code

Yeah, if it will only be a number

Dim cap As Double

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"BRC" wrote in message
ups.com...
Sorry about that, I had removed the "long" from the dim statement. I
just had "dim cap " which I believe initializes a varient. Should I be
using something else there? Thanks
BRC
JMay wrote:
Dim cap as Long <<< means cap is a long INTEGER!! (no decimals) RIGht?
HTH

"BRC" wrote:

sub filldata

dim cap as long
' for purpose this of illustration F16= .15
cap = Sheet4.Range("f16").Value
' to verify that cap is initialized
Msgbox(cap)
' for purpose of illustration c6=.20
Range("d6").Formula = "=IF(c6<0,0,IF(c6cap,cap,c6))"
end sub

If I replace "cap" with a number ( .15) it works fine but when I try to
use the variable cap I get a #name? error in the cells.
I believe I may not using correct punctuation around the variable. Any
suggestions Thanks
BRC





  #5   Report Post  
Posted to microsoft.public.excel.programming
BRC BRC is offline
external usenet poster
 
Posts: 10
Default How to use variable in code

Thank you all. The turning cap into a string worked. Thanks again. BRC
Bob Phillips wrote:
Yeah, if it will only be a number

Dim cap As Double

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"BRC" wrote in message
ups.com...
Sorry about that, I had removed the "long" from the dim statement. I
just had "dim cap " which I believe initializes a varient. Should I be
using something else there? Thanks
BRC
JMay wrote:
Dim cap as Long <<< means cap is a long INTEGER!! (no decimals) RIGht?
HTH

"BRC" wrote:

sub filldata

dim cap as long
' for purpose this of illustration F16= .15
cap = Sheet4.Range("f16").Value
' to verify that cap is initialized
Msgbox(cap)
' for purpose of illustration c6=.20
Range("d6").Formula = "=IF(c6<0,0,IF(c6cap,cap,c6))"
end sub

If I replace "cap" with a number ( .15) it works fine but when I try to
use the variable cap I get a #name? error in the cells.
I believe I may not using correct punctuation around the variable. Any
suggestions Thanks
BRC




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
can i link a variable cost code with a variable sum I need help!! Excel Discussion (Misc queries) 0 August 1st 08 11:40 AM
Variable within the code ngedwin Excel Programming 2 July 10th 05 10:31 AM
variable code?? Paul Excel Discussion (Misc queries) 1 April 5th 05 06:37 PM
variable code Paul Excel Programming 2 April 5th 05 05:27 PM
Variable in a VB Code Michael Kintner Excel Programming 1 January 5th 04 02:29 PM


All times are GMT +1. The time now is 08:31 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"