+ Reply to Thread
Results 1 to 7 of 7

Active Row Query

  1. #1
    Registered User
    Join Date
    02-07-2007
    Posts
    37

    Active Row Query

    Hi,

    I am trying to write a Macro which inserts a row below the Active Cell and then copys a pre-defined row (which contains formula's) and then pastes it into the new row.

    The problem I have is that once I move away from the newly inserted row (to copy the row containing the formua's) how do I get excel to go back to the newly inserted row, as it no longer has a point of reference.

    Hope someone can help

    Thanks

  2. #2
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Active Row Query

    Hi,

    Without looking at your code, it is a bit difficult to give you a precise answer ...

    But in generic terms, you always store in a variable of yours a given row number for example ...

    HTH

  3. #3
    Registered User
    Join Date
    03-24-2010
    Location
    Pune, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    36

    Lightbulb Re: Active Row Query

    Hi daz_uk,

    Try below code:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-07-2007
    Posts
    37

    Re: Active Row Query

    Hi Nchavan,

    Thanks for the code.

    I have added your code to my code, but have 1 final question.

    Dim i As Integer, j As Integer
    'i contains the row number of the activecell
    ThisWorkbook.Sheets(1).Activate
    i = ActiveCell.Row
    'i = ThisWorkbook.Sheets(1).ActiveCell.Row
    ThisWorkbook.Sheets(1).Cells(i + 1, 1).EntireRow.Insert shift:=xlDown
    'j contains the row number of the newly inserted row
    j = i + 1
    'Do your stuff here now as you have j holding the reference for the newly added row after the activecell
    ActiveCell.Offset(1).EntireRow.Insert
    Range("A1:AN1").Select
    Selection.Copy
    Selection j
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Application.CutCopyMode = False
    End Sub

    I know the syntax is wrong (I have highlighted it in bold) but how do reselect "j" in order to do my paste?

    Thanks

  5. #5
    Registered User
    Join Date
    03-24-2010
    Location
    Pune, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    36

    Thumbs up Re: Active Row Query

    Hi daz_uk,

    As the variable j is holding the row number of newly added row you have to use it as below:
    Please Login or Register  to view this content.
    Cheerz,
    ~Ne@l

    *********************************************************************
    Save a tree. Please think before you print this post and/or attachments.

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Active Row Query

    Just FYI, you can simplify your code to:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  7. #7
    Registered User
    Join Date
    02-07-2007
    Posts
    37

    Re: Active Row Query

    wow, thanks everyone for the help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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