Consulting

Results 1 to 6 of 6

Thread: VBA find the FIRST real row

  1. #1
    VBAX Newbie
    Joined
    May 2016
    Posts
    4
    Location

    VBA find the FIRST real row

    Need alot of help
    what's wrong with my code???? i need it to cut one by one A2, A3, A4, .... and paste to A1
    im still new to VBA and no one in my office seems to be able to have the time to help me u

    -----------------------------------------------------------
    Sub Macro1()
    '
    ' Macro1 Macro
    '
    ' Keyboard Shortcut: Ctrl+g
    '
        Range("A2").Select
        Selection.Cut
        Range("A1").Select
        ActiveSheet.Paste
    
    
    Sub FindNextRow()
       
        Dim LastRow As Long
        Dim LastCol As Long
        
            ' Find the FIRST real row
        LastRow = ActiveSheet.Cells.Find(What:="*", _
          SearchDirection:=xlPrevious, _
          SearchOrder:=xlByRows).Row
       
            ' Find the LAST real column
        LastCol = ActiveSheet.Cells.Find(What:="*", _
          SearchDirection:=xlNext, _
          SearchOrder:=xlByColumns).Column
            
       'Select the ACTUAL Used Range as identified by the
       'variables identified above
    ActiveSheet.Cells(LastRow - 1, 1).Select
     
    
    
    End Sub
    Last edited by QuaDen; 05-03-2016 at 06:33 PM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    1. Are you missing an 'End Sub'?

    2. You said Find First real row, but variables are LastRow and LastCOl

    3. "i need it to cut one by one A2, A3, A4, .... and paste to A1" -- not sure what this means

    4. Can you attach a small workbook showing what you have and what you want?



    Sub Macro1() 
         '
         ' Macro1 Macro
         '
         ' Keyboard Shortcut: Ctrl+g
         '
        Range("A2").Select 
        Selection.Cut 
        Range("A1").Select 
        ActiveSheet.Paste 
    End Sub                           ' <<----------------------------------------------------------
         
        Sub FindNextRow() 
             
            Dim LastRow As Long 
            Dim LastCol As Long 
             
             ' Find the FIRST real row
            LastRow = ActiveSheet.Cells.Find(What:="*", _ 
            SearchDirection:=xlPrevious, _ 
            SearchOrder:=xlByRows).Row 
             
             ' Find the LAST real column
            LastCol = ActiveSheet.Cells.Find(What:="*", _ 
            SearchDirection:=xlNext, _ 
            SearchOrder:=xlByColumns).Column 
             
             'Select the ACTUAL Used Range as identified by the
             'variables identified above
            ActiveSheet.Cells(LastRow - 1, 1).Select 
             
             
             
        End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    May 2016
    Posts
    4
    Location
    Hi Paul

    This is my workbook
    Attached Files Attached Files

  4. #4
    VBAX Newbie
    Joined
    May 2016
    Posts
    4
    Location
    I'm test this code but it's not work:

     
    ' Find the FIRST real row
        FirstRow = ActiveSheet.Cells.Find(What:="*", _
          SearchDirection:=xlNext, _
          SearchOrder:=xlByRows).Row
          
    ' Find the FIRST real column
        FirstCol = ActiveSheet.Cells.Find(What:="*", _
          SearchDirection:=xlNext, _      
     SearchOrder:=xlByColumns).Column

  5. #5
    Even with the worksheet it is difficult to understand the aim of the process.
    However, based on your original post I think the following may be what you require.

    Range("A1").Delete Shift:=xlUp
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  6. #6
    VBAX Newbie
    Joined
    May 2016
    Posts
    4
    Location
    Quote Originally Posted by gmayor View Post
    Even with the worksheet it is difficult to understand the aim of the process.
    However, based on your original post I think the following may be what you require.

    Range("A1").Delete Shift:=xlUp
    wow, thank gmayor so much, that's my repuire

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •