+ Reply to Thread
Results 1 to 4 of 4

filling cell in column "a" if data present in column "b" issue.

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    18

    filling cell in column "a" if data present in column "b" issue.

    hello,
    i am working on a spreadsheet for work and one of the tasks I'm trying to accomplish is when i fillout a cell in the "Part #" column(B) to auto fill the equivalent cell in the "CUST #" Column(m) with the number 808849. i have this working except it over rights my header row(row 7) because the label "PART #" means that cell is filled so it overrights "CUST #". i have tried to limit the range to row 8+ but it then freaks out and dumps 808849 into a bunch of random fields. in the attached file i had to sanitize it due to confidentiality. if it would help i can fill it back up with fake info. i know everyone says this but i am pretty new to VBA scripting so i'm sure I'm missing something very obvious, also i know this script is a bit useless by itself but it's only step one to a much larger intent.
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim RNG As Range
    'Dim ws As Worksheet
    'Set ws = Worksheets("Sheet1")
    'Dim lastRow As Long
    
        Application.EnableEvents = False
        On Error Resume Next
        'lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
        'MsgBox (lastRow)
        Set RNG = Range("B:B").SpecialCells(xlConstants)
        
        If Not RNG Is Nothing Then
            RNG.Offset(, 11) = "808849"
        Else
            Cells.ClearContents
        End If
            
            Application.EnableEvents = True
        
    End Sub
    Blank_template.xlsm

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: filling cell in column "a" if data present in column "b" issue.

    Hi Tim

    I cannot see where you are controlling your macro.

    This is your basic problem. Insert the following line.

    'if row <=8 or comumn <> b then exit
    if target.row<9 or target.column <> 2 then exit sub


    
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim RNG As Range
    'Dim ws As Worksheet
    'Set ws = Worksheets("Sheet1")
    'Dim lastRow As Long
    
    if target.row<9 or target.column <> 2 then exit sub
    
        Application.EnableEvents = False
        On Error Resume Next
        'lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
        'MsgBox (lastRow)
        Set RNG = Range("B:B").SpecialCells(xlConstants)
        
        If Not RNG Is Nothing Then
            RNG.Offset(, 11) = "808849"
        Else
            Cells.ClearContents
        End If
            
            Application.EnableEvents = True
        
    End Sub

  3. #3
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: filling cell in column "a" if data present in column "b" issue.

    Could this be of help?

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim Rng As Range
        On Error Resume Next
        Set Rng = Range("B:B").SpecialCells(xlConstants)
        If Not Intersect(Target, Rng) Is Nothing Then
            Application.EnableEvents = False
            Target.Offset(0, 11) = "808849"
            Application.EnableEvents = True
        End If
    End Sub

  4. #4
    Registered User
    Join Date
    11-06-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: filling cell in column "a" if data present in column "b" issue.

    thanks for the help this solved my problem completely

+ 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. [SOLVED] If there is any text in column "A$" on "sheet1" then move cell to column "A$" on "sheet2"
    By ckgeary in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2013, 08:28 PM
  2. Replies: 2
    Last Post: 06-06-2013, 12:45 PM
  3. [SOLVED] Delete row if cell in Column N equal "Different" or Column P equals "Blank"
    By Cyberpawz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2012, 08:25 AM
  4. Replies: 3
    Last Post: 02-16-2011, 02:55 PM
  5. Replies: 1
    Last Post: 07-16-2010, 02:44 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