Results 1 to 10 of 10

Thread: Transferring a "score" achieved to an excel cell using offset and count...

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Transferring a "score" achieved to an excel cell using offset and count...

    Hi all new to this forum, I have a headache of code here I do hope someone can help me out a little with it.

    Within my program I have a scoring system using a counter determined by an answer i.e. if a combobox value = yes then add one to the counter.

    A percentage is then calculated and displayed on an output worksheet. The answers are displayed on the output sheet and stored in a table format, when another set of results is entered it overwrites the output sheet and stores on the next line of the table using:
    Code:
    Dim e As Range, el As Range                             
    Set e = Worksheets("SHEETNAME").Range("A3:AM3").CurrentRegion    
    Set el = e.Offset(e.Rows.Count, 0)
    I am using arrays to allow the user to pick a row from results in the table and copy across and overwrite the output sheet.
    I want the percentage calculated to display in the end available cell ie. AK3then AK4 coinciding with the results on the same row(at the end) this is calculated within a separate sub function which creates the problem.
    I am using:
    Code:
    Set e = Worksheets("SHEETNAME").Range("AN3").CurrentRegion
    Set el = e.Offset(e.Rows.Count, 0)
    el.Cells(1).Value = Score
    but this puts it on the next line i.e. A4. It must be due to there already being results on that row so its counting this then adding to the next one. I know i need to tweak the
    Code:
    e.Offset(e.Rows.Count, 0)
    But I cannot figure out how to.
    I have tried to attack the issue using
    Code:
    Set e = Worksheets("Letter").Range("AN3:AN600").CurrentRegion
    Set el = e.Offset(e.Rows.Count, 39)
    el.Cells(1).Value = Score
    ActiveCell.Cut
    Range("AN3:AN600").Offset(-1, 0).Select
    ActiveSheet.Paste
    But this also does not work can someone help me out? I know I am nearly there so frustrating!!!

    Thanks
    Last edited by DogDee; Feb 8th, 2010 at 09:40 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    i have not figured out where you are trying to put the new data

    Set el = e.Offset(e.Rows.Count, 39)
    this sets a range the same size as e, not a single cell
    msgbox el.address
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    Quote Originally Posted by westconn1 View Post
    i have not figured out where you are trying to put the new data

    this sets a range the same size as e, not a single cell
    msgbox el.address
    I have used 39 as the cell number as it moves the data across that many cells but it's on the row below where i want the data to be but in the correct column. That is why i tried using the offset -1 to bring the data up a row.

    Hope that makes sense.

    I do not understand this coding below, can you further explain please?

    msgbox el.address

    Thanks

  4. #4
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    Are you trying to put the result in the first available cell to the right of the data in a particular row?

    Does each row contain the same number of filled columns, or does the number vary?

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    Quote Originally Posted by vbfbryce View Post
    Are you trying to put the result in the first available cell to the right of the data in a particular row?
    Yes in the cell to the right of the row, but the row changes by adding another set of results ie. adds to the next row (results 1 in row 3, results 2 in row 4 etc)


    Does each row contain the same number of filled columns, or does the number vary?
    No not actual filled columns (dependent on results) but the column letter will stay the same all the time for the data to be put in.
    Last edited by DogDee; Feb 8th, 2010 at 11:00 AM.

  6. #6
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    So when you say this:

    "I am using arrays to allow the user to pick a row from results in the table and copy across and overwrite the output sheet."

    you mean that by picking a row in the table they are determining which row in the spreadsheet to write to (or overwrite)?

    For example, whatever they picked in the table tells your app to overwrite row 17, for example, on the output spreadsheet. So you need to go to the first empty cell in row 17 and put a calculated value in that cell.

    Sound right, or did I misunderstand something?

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    msgbox el.address
    it would just demonstrate the address of the range el you set, showing the included cells
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    Quote Originally Posted by vbfbryce View Post
    So when you say this:

    "I am using arrays to allow the user to pick a row from results in the table and copy across and overwrite the output sheet."

    you mean that by picking a row in the table they are determining which row in the spreadsheet to write to (or overwrite)?

    For example, whatever they picked in the table tells your app to overwrite row 17, for example, on the output spreadsheet. So you need to go to the first empty cell in row 17 and put a calculated value in that cell.

    Sound right, or did I misunderstand something?
    Yes and no,

    No because by selecting a row on the table and utilising the array functions the whole of the output sheet changes in accordance with the results from that one row in the table. The table is used for storing the data and the output sheet is used to show one row of data in a user friendly format.

    Yes because it's the first empty cell in that row within the table that I want the calculated value to be written to.

    I think the problem arises from the fact that when results are inputted they are written to the table first, from the table the results are then written to the output sheet and the calculated is created from these results on the output sheet. I then want this to be added to the first empty cell in that corresponding row in the table (where the results have already been written) and I think this is why I am struggling to get it to write to the same row (the coding keeps adding the calculated to the next row and just puts that data in on that row nothing else will write to it, anything else skips to next row).


    Hope this makes sense.

    Thanks

  9. #9
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    Ok, I think I gotcha now.

    Could you attach more of your code to give us a better view of how you're trying to do it?

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    7

    Re: Transferring a "score" achieved to an excel cell using offset and count...

    Hi

    Just an update, I solved it by using the same coding used to write to the output sheet and change it to write to the table sheet directly.


Posting Permissions

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



Click Here to Expand Forum to Full Width