+ Reply to Thread
Results 1 to 10 of 10

Help with a code

  1. #1
    Registered User
    Join Date
    09-06-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    8

    Help with a code

    I have spreadsheets with similar codes for the same outcome: Once I click on the cell I register the info in another cell.

    Spreadsheet A register the info in the cell C4
    Spreadsheet B register the info in the cell C9

    However only the code in the spreadsheet A works. I don't know what is wrong with the code in the spreadsheet B


    Someone help me please!!!




    Spreadsheet 1

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Target_Row = Target.Row
    Target_Column = Target.Column


    If Target.Count = 1 Then

    If (Target_Row = 15) And (Target_Column = 8) Then
    Line_Code = Sheets("A").Cells(Target_Row, 8).Text
    Sheets("Aux").Range("C4").Value = Line_Code
    End If

    If (Target_Row = 15) And (Target_Column = 11) Then
    Line_Code = Sheets("A").Cells(Target_Row, 11).Text
    Sheets("Aux").Range("C4").Value = Line_Code
    End If


    End If

    End Sub


    Spreadsheet B

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Target_Row = Target.Row
    Target_Column = Target.Column

    If Target.Count = 1 Then 'Make sure only one cell is selected


    If (Target_Row = 15) And (Target_Column = 9) Then
    Line_Code = Sheets("B").Cells(Target_Row, 9).Text
    Sheets("Aux").Range("C9").Value = Line_Code
    End If

    If (Target_Row = 15) And (Target_Column = 15) Then
    Line_Code = Sheets("Reclaim").Cells(Target_Row, 15).Text
    Sheets("Aux").Range("C9").Value = Line_Code
    End If



    Application.ScreenUpdating = True

    End If

    End Sub

  2. #2
    Registered User
    Join Date
    09-06-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    8

    Re: Help with a code

    Please... someone???

  3. #3
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Help with a code

    Firstly, when posting code you need to surround it by [ code ] & [ /code ] tags

    Please Login or Register  to view this content.
    Secondly, what cell addresses are you expecting this to happen for? The way you're addressing cells in your code there, while not being an incorrect way to reference them, is a little odd. Id write it like this:


    Spreadsheet A (translating your target row and column to an actual address):
    Please Login or Register  to view this content.
    Spreadsheet B:
    Please Login or Register  to view this content.

    And are you absolutely sure you want .text and not .value?

    .Text gives you a string representing what is displayed on the screen for the cell. Using .Text is usually a bad idea because you could get ####

    Finally, spreadsheet B is pulling data from two different sheets. "B" and "Reclaim". is this correct?
    Last edited by BellyGas; 09-06-2017 at 06:10 AM.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Help with a code

    FYI, you can simplify that code thus
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Help with a code

    bearing in mind spreadsheet B is specifying data from two different sheets.....that may not be the case.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Help with a code

    Hence I did not include the code for that event.

  7. #7
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Help with a code

    I get ya. I'm sticking with the view that the OP may not be intimately familiar with coding and therefore both macros should be as similar as possible just for the sake of clarity.

  8. #8
    Registered User
    Join Date
    09-06-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    8

    Re: Help with a code

    BellyGas. Thank you so much for your help about the code and tips in how to post in here!!! I really appreciate.

  9. #9
    Registered User
    Join Date
    09-06-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    8

    Re: Help with a code

    xlnitwit. Thank you so much your help and comments about the code. I appreciate very much

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: Help with a code

    @SimoneO

    Please take a few minutes to read our forum rules as you may have overlooked them when you signed onto this forum. Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.



    Your post does not comply with Rule 3 of our Forum [/I]RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 01-07-2016, 12:25 PM
  2. [SOLVED] Need help with VBA code. Tons of code seperated in two, second part of code doesn't work.
    By FragaGeddon in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 11-30-2015, 11:46 AM
  3. [SOLVED] Pattern Building VBA Code - Working code, would like to use cleaner code
    By Benisato in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2015, 03:05 PM
  4. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  5. [SOLVED] VBA code for assigning a numeric code to text; then numeric code populates table
    By cteaster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2014, 08:01 PM
  6. Replies: 2
    Last Post: 03-09-2013, 04:30 AM

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