Results 1 to 7 of 7

Help moving a VBA code from one workbook to another- with different sheet name

Threaded View

  1. #1
    Registered User
    Join Date
    07-11-2014
    Location
    Surprise,AZ
    MS-Off Ver
    2010
    Posts
    53

    Help moving a VBA code from one workbook to another- with different sheet name

    i need help using this code in another work book with different name. When I change the name of the sheet 2 to the new sheet of Table- it doent work the cells go blank and code doesn;t work. Can someone tell me what I'm doing wrong?


    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range, LR As Long, NR1 As Long, NR2 As Long
    
    If Not Intersect(Target, Range("E4")) Is Nothing Then
        Application.EnableEvents = False
        Range("E21:N30").ClearContents
        NR1 = 21
        NR2 = 21
        With Sheets("Sheet2")
            .AutoFilterMode = False
            .Rows(1).AutoFilter 3, "*" & Range("E4") & "*"
            LR = .Range("C" & .Rows.Count).End(xlUp).Row
            If LR > 1 Then
                For Each cell In .Range("M2:M" & LR).SpecialCells(xlVisible)
                    Select Case UCase(cell.Value)
                        Case "ME"
                            Range("E" & NR1).Value = .Cells(cell.Row, "K").Value
                            Range("H" & NR1).Value = .Cells(cell.Row, "B").Value
                            Range("I" & NR1).Value = .Cells(cell.Row, "I").Value
                            NR1 = NR1 + 1
                        Case "THEM"
                            Range("J" & NR2).Value = .Cells(cell.Row, "K").Value
                            Range("M" & NR2).Value = .Cells(cell.Row, "B").Value
                            Range("N" & NR2).Value = .Cells(cell.Row, "I").Value
                            NR2 = NR2 + 1
                    End Select
                Next cell
            Else
                Range("E21") = "none"
            End If
            .AutoFilterMode = False
        End With
        Application.EnableEvents = True
    End If
    End Sub
    Last edited by air044; 12-02-2014 at 12:06 PM.

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: 10-09-2012, 08:40 PM
  2. Moving a sheet module from one workbook to another
    By bobaftt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2011, 10:01 AM
  3. moving a sheet to new workbook
    By share knowledge in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-26-2011, 08:16 AM
  4. Moving a protected sheet to a different workbook
    By TPD in forum Excel General
    Replies: 0
    Last Post: 02-13-2007, 10:59 AM
  5. Can I prevent a sheet from moving within a workbook?
    By JDGUILTY in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2005, 02:06 PM

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