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.
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
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:
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.Cells(2,1).Value = "y"
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.
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks