+ Reply to Thread
Results 1 to 4 of 4

Thread: Setting cell values

  1. #1
    Registered User
    Join Date
    11-24-2011
    Location
    Utah, USA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Setting cell values

    Hey there,

    I'm trying to set some cell values with a function (or sub) in a module - this seems to be an extremely easy thing to do, but for some reason it just won't work. I've tried 'range(a,b).value=...', 'cells(a,b).value=...', 'activecell.offset(a,b)=...', and it just kills the program. '.select' doesn't hurt, so it seems that the problem is only at the part where it sets the value.

    Strangely enough, it has worked in debug. I put the code in its own sub, and though the first time around it stopped, as I kept hitting F8 it returned to the top of the sub and went right through the problem area. Unfortunately, it would not exit the sub - it just kept looping around, so the rest of the program never executed. When I returned to the Excel sheet, the cell value was changed!

    I have no clue what's going on. I've seen this done quite easily before, and I even have a program that works just fine. Any attempt to imitate or reuse it ends with the same problem.

    There is no error message or anything. Just a program that won't complete and a cell that won't change. Any help would be greatly appreciated. Thanks!

    Here's an example of the code:

    Sub test()

    Range("C3").Select
    Range("C3").Value = "test"

    End Sub

    But I've tried just about every variation of this as I could find.
    Last edited by cocojack; 11-24-2011 at 04:51 PM.

  2. #2
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,155

    Re: Setting cell values

    Hi cocojack,

    welcome to the forum
    Whats the code?
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  3. #3
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,238

    Re: Setting cell values

    Any help with what? You haven't shared the code, you haven't uploaded a sample workbook. You've just said you have a problem.

    You use:

    Range("A2").Value = "x"

    or:

    Cells(2,1).Value = "y"
    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook. Don't upload a picture when you have a workbook. None of us is inclined to recreate your data. Upload the workbook and manually add an 'after' situation so that we can see what you expect. In addition clearly explain how you get the results.

    To attach a file to your post, you need to be using the main 'New Post' or 'New Thread' page and not 'Quick Reply'.
    To use the main 'New Post' page, click the 'Post Reply' button in the relevant thread.

    On this page, below the message box, you will find a button labelled 'Manage Attachments'.
    Clicking this button will open a new window for uploading attachments.

    You can upload an attachment either from your computer or from another URL by using the appropriate box on this page.
    Alternatively you can click the Attachment Icon to open this page.

    To upload a file from your computer, click the 'Browse' button and locate the file.

    To upload a file from another URL, enter the full URL for the file in the second box on this page.
    Once you have completed one of the boxes, click 'Upload'.

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.

  4. #4
    Forum Guru
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,110

    Re: Setting cell values

    If it keeps returning to the top without an error, I would guess that it's in Worksheet_Change() and every time you put a value into a cell it triggers Worksheet_Change() again that puts a value into a cell which triggers Worksheet_Change().....etc. (IOW an endless loop).

    If that's the case put "Application.EnableEvents = False" at the top and "Application.EnableEvents = True" at the bottom of the sub. This will prevent it from triggering itself over & over again in an endless loop.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

+ 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.2.0