+ Reply to Thread
Results 1 to 4 of 4

call variable into cell value

  1. #1
    Forum Contributor
    Join Date
    03-27-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    290

    call variable into cell value

    I know this is a silly question but I dont know how to call a variable into a cell...

    I have a variable set as Monthrow = Range("G16").Row + 14
    Another is Countrec = 242
    then I want to use
    Range("C" & Monthrow).Value = Countrec

    but there appears to be no change in C16 (Monthrow is currently 16)

    how do I enter a variable into a cell as a value?

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: call variable into cell value

    Hi there,

    The syntax is correct - put the Monthrow in a message box to validate its value i.e.

    Please Login or Register  to view this content.
    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: call variable into cell value

    Hi.

    Sorry but Monthrow <> 16. You get Monthrow =30 from
    Please Login or Register  to view this content.
    line.
    Click *, if my suggestion helps you. Have a good day!!

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: call variable into cell value

    penfold,

    I am not entirely sure about your question.

    Please Login or Register  to view this content.
    the above code takes the row number of G16 (which is not surprisingly always 16) and then add the value 14. SO MonthRow will always have the value 30 after this line. What I think you want to do is take the VALUE shown in G16 and add 14.

    Please Login or Register  to view this content.
    If you now want to assign the value of Countrec to a cell in column C on the row number that equals the value of MonthRow the code would be

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  5. #5
    Forum Contributor
    Join Date
    03-27-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    290

    Re: call variable into cell value

    I found it better to do Debug.Print Monthrow but that gave me the correct answer

    The problem was something more basic that I just didnt realise until i clicked on the cell...

    it was a merged cell so it didnt like it. I must have accidently merged it at some previous stage and forgot about it.
    silly mistake really but i guess thats a reason for vba to not change that specific cell!

    EDIT for ollieB, i made a mistake typing in the code into the forums, it was .Value :P I was trying to cut out some information from the macro so i hand wrote that bit!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1