Consulting

Results 1 to 3 of 3

Thread: Sleeper: Cascade String concatenation problem

  1. #1
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    2
    Location

    Question Sleeper: Cascade String concatenation problem

    Hi everyone, I am pretty new to vba but I have been coding for a long time in c/c++. What I want to do is :
    When I write on a selected cell for example INTC I want the cell right next to it to display sometihng like FIBBONACCI('INTC') <= 50

    So what I did is : use Worksheet with change and this is the code :

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim SymbolName As String
    SymbolName = Target.Value
    ActiveCell.Offset(-1, 1) = "FIBBONACCI(" & SymbolName & " ) <= 50"
    End Sub
    But the result keeps cascadiing :


    FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACC I(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONA CCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBO NACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIB BONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(F IBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI (FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(FIBBONACCI(intc ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50 ) <= 50

    What is wrong in my code? Thank you very much
    Last edited by Paul_Hossler; 01-03-2020 at 04:09 PM. Reason: CODE tags

  2. #2
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    2
    Location
    This is the unwanted result what I want is only FIBBONACCI('INTC') <= 50 Thanks again
    Attached Images Attached Images

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    This code was event driven and each time you changed the WS it was called again
    Temporarily disable events with Application.EnableEvents = False


    Use Target.Offset

    .Offset should be (0,1) meaning 'same row but one column to the right'


    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim SymbolName As String
    
    SymbolName = Target.Value
    
    Application.EnableEvents = False
    Target.Offset(0, 1) = "FIBBONACCI(" & SymbolName & " ) <= 50"
    
    Application.EnableEvents = True
    End Sub


    Didn't test
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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