+ Reply to Thread
Results 1 to 5 of 5

How to repeat the same VBA in a single sheet?

  1. #1
    Registered User
    Join Date
    03-28-2013
    Location
    thailand
    MS-Off Ver
    Excel 2003
    Posts
    25

    How to repeat the same VBA in a single sheet?

    How to have a few of these worksheet changes in one single sheet? I want to repeat the same macro for cell G1 and have the values pasted to G2


    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range
    Set KeyCells = Range("A1")
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
    Is Nothing Then
    Range("A2").Select
    Selection.Copy
    Range("A1048576").End(xlUp).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    End If
    End Sub

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to repeat the same VBA in a single sheet?

    Try something like this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,090

    Re: How to repeat the same VBA in a single sheet?

    Maybe:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    03-28-2013
    Location
    thailand
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: How to repeat the same VBA in a single sheet?

    Thank you. The code works. Another problem came about.

    The cell A1 is linked to an external source (RTD) but when the cell updates, the cut and copy does not work. It only works when I key in different values into cell A1.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,090

    Re: How to repeat the same VBA in a single sheet?

    A worksheet change event only fires when the value is changed manually, or using code. It wouldn't fire, for example, if you had a formula in cell A1.

    You might have to resort to checking cell A1 in Calculation event.

    Regards, TMS

+ 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] Pull data if there is any from a single column in multiple worksheets into a single sheet
    By bcas77 in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 07-11-2013, 01:22 PM
  2. [SOLVED] Find missing values in sequences, repeat for many ranges in a single sheet
    By KRMd in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2012, 08:36 PM
  3. how can I repeat row heights in the same sheet
    By Khalil in forum Excel General
    Replies: 1
    Last Post: 12-06-2005, 03:40 PM
  4. In Excel Sheet any digit repeat
    By Haldun Alay in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 09:05 AM
  5. [SOLVED] Repeat value in the same cell on each sheet
    By Katherine in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-15-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