+ Reply to Thread
Results 1 to 8 of 8

How to add new value with Previous value

Hybrid View

  1. #1
    Registered User
    Join Date
    03-12-2012
    Location
    Dubai
    MS-Off Ver
    Excel 2003
    Posts
    55

    How to add new value with Previous value

    Can anyone help me on this , how to fix this . i want to Add new value with Previous Value

    Capture.PNG

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim FixRange As Range
    
     On Error Resume Next
       If Not Application.Intersect(FixRange, Range(Target.Address)) Is Nothing Then
                If Target.Value = "S" Then
                   Target.Offset(0, -1).Value = "Master." & Target.Offset(0, -1).Value
                End If
                
                If Target.Value = "D" Then
                    Target.Offset(0, 1).Value = "MISS." & Target.Offset(0, -1).Value
                End If
                
        End If
      Target = UCase(Target)
        End Sub
    Attached Images Attached Images
    Last edited by sijostephen; 06-08-2019 at 08:39 AM. Reason: Admin Instruction

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,158

    Re: How to add new value with Previous value


    Try:
    Option Explicit
    
    Const FixRangeAddress As String = "B2:B4"
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range(FixRangeAddress)) Is Nothing Then Exit Sub
        
        Application.EnableEvents = False
        
        If UCase(Target.Value) = "D" Then
            Target.Offset(0, 1).Value = "MISS." & Target.Offset(0, -1).Value
        ElseIf UCase(Target.Value) = "S" Then
            Target.Offset(0, -1).Value = "Master." & Target.Offset(0, -1).Value
        End If
        Target.Value = UCase(Target.Value)
        
        Application.EnableEvents = True
    End Sub

  3. #3
    Registered User
    Join Date
    03-12-2012
    Location
    Dubai
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: How to add new value with Previous value

    Sorry Sir , i changed but no error and no changes here is the file attached for ur reference
    Attached Files Attached Files

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,024

    Re: How to add new value with Previous value

    @sijostephen

    Administrative Note:

    You have been a member here long enough to know our forum rules.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Click on Edit to open your post, 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

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    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

  5. #5
    Registered User
    Join Date
    03-12-2012
    Location
    Dubai
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: How to add new value with Previous value

    Thank you for ur information , i changed ..

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,158

    Re: How to add new value with Previous value

    Quote Originally Posted by sijostephen View Post
    ... no error and no changes ...
    For me this code works, please try again in this way:
    Option Explicit
    
    Const FixRangeAddress As String = "F3:F400"
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range(FixRangeAddress)) Is Nothing Then Exit Sub
        If Target.Cells.Count > 1 Then Exit Sub
        If Trim(Target.Value) = "" Then Exit Sub
        
        Application.EnableEvents = False
        
        If Left(UCase(Target.Value), 1) = "D" Then
            Target.Offset(0, 1).Value = "MISS." & Target.Offset(0, -1).Value
            Target.Value = "D"
        ElseIf Left(UCase(Target.Value), 1) = "S" Then
            Target.Offset(0, -1).Value = "Master." & Target.Offset(0, -1).Value
            Target.Value = "S"
        End If
        
        Application.EnableEvents = True
    End Sub

  7. #7
    Registered User
    Join Date
    03-12-2012
    Location
    Dubai
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: How to add new value with Previous value

    Thank you sir, is it possible to all target to uppercase automatically ?

  8. #8
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,158

    Re: How to add new value with Previous value

    Try:
    Option Explicit
    
    Const FixRangeAddress As String = "F3:F400"
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range(FixRangeAddress)) Is Nothing Then Exit Sub
        If Target.Cells.Count > 1 Then Exit Sub
        If Trim(Target.Value) = "" Then Exit Sub
        
        Application.EnableEvents = False
        
        If Left(UCase(Target.Value), 1) = "D" Then
            Target.Offset(0, 1).Value = "MISS." & UCase(Target.Offset(0, -1).Value)
            Target.Value = "D"
        ElseIf Left(UCase(Target.Value), 1) = "S" Then
            Target.Offset(0, -1).Value = "MASTER." & UCase(Target.Offset(0, -1).Value)
            Target.Value = "S"
        End If
        
        Application.EnableEvents = True
    End Sub

+ 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: 0
    Last Post: 02-25-2015, 01:02 PM
  2. Selection.Previous/ActiveCell.Previous Problem
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-21-2014, 02:05 AM
  3. [SOLVED] Find certain word, copy and paste cell in previous row if previous row is blank
    By steven_e in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2013, 12:53 PM
  4. [SOLVED] Find last previous non blank value and summarise previous 6 months
    By Lady_Shaz in forum Excel General
    Replies: 7
    Last Post: 12-11-2012, 06:20 AM
  5. Replies: 1
    Last Post: 04-30-2012, 06:02 AM
  6. Replies: 0
    Last Post: 10-14-2011, 12:09 PM
  7. Replies: 1
    Last Post: 12-01-2010, 03:20 PM

Tags for this Thread

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