+ Reply to Thread
Results 1 to 10 of 10

Copy a row from excel which have two space at the starting place

Hybrid View

  1. #1
    Registered User
    Join Date
    12-03-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Copy a row from excel which have two space at the starting place

    Hi All,

    I need to copy a row from excel to another sheet when any row have one space before the word in the column A.

    E.g:
    Column A
    Value 1
    Value 2 (this row have a space before the word value 2)
    Value 3
    Value 4

    I need to copy row 2 since the " Value 2" have once space at the starting

    Please help me with this scenario.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Copy a row from excel which have two space at the starting place

    for count = 1 to range("A" & rows.count).end(xlup).row
      if left(Range("A" & count),1) = " " then rows(count).copy
    next

  3. #3
    Registered User
    Join Date
    12-03-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Copy a row from excel which have two space at the starting place

    Hi Thanks for the quick reply,

    I tired using your code: I need to copy these selection into a sheet2 of the same excel, i tried the below code, but get a junk result
    Please help me with this.

    Sub copy()
    For Count = 1 To Range("A" & Rows.Count).End(xlUp).Row
    If Left(Range("A" & Count), 1) = " " Then Rows(Count).copy
    Worksheets("Sheet2").Activate
    ActiveSheet.Paste Destination:=Worksheets("Sheet2").Rows(1)
    Next
    End Sub

  4. #4
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Copy a row from excel which have two space at the starting place

    Sub copy()
    For Count = 1 To Range("A" & Rows.Count).End(xlUp).Row
    If Left(Range("A" & Count), 1) = " " Then 
    Rows(Count).copy Sheet2.cells(Rows.count, 1).end(xlup).offset(1,0)
    Next
    End Sub
    Give Feedback and Click(*)

  5. #5
    Registered User
    Join Date
    12-03-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Copy a row from excel which have two space at the starting place

    When i ran this code i got compile error saying "Next without for"

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Copy a row from excel which have two space at the starting place

    Sorry, try:

    Sub copy()
    For Count = 1 To Range("A" & Rows.Count).End(xlUp).Row
    If Left(Range("A" & Count), 1) = " " Then 
    Rows(Count).copy Sheet2.cells(Rows.count, 1).end(xlup).offset(1,0)
    end if
    Next
    End Sub

  7. #7
    Registered User
    Join Date
    12-03-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Copy a row from excel which have two space at the starting place

    Thanks a lot, works perfect

  8. #8
    Registered User
    Join Date
    11-07-2012
    Location
    Europe
    MS-Off Ver
    Excel 2010
    Posts
    53

    Re: Copy a row from excel which have two space at the starting place

    I have played a little with the code of "yudlugar" and this is what works with me:

    Sub copy()
        For Count = 1 To Range("A" & Rows.Count).End(xlUp).Row
            Sheets(1).Activate
            If Left(Range("A" & Count), 1) = " " Then
                Sheets(1).Activate
                Rows(Count).copy
                Sheets(2).Activate
                Cells(Count, 1).Activate
                ActiveSheet.Paste
            End If
        Next
    End Sub
    edit: With the original post I get 424 error on line 4.

  9. #9
    Registered User
    Join Date
    12-03-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Copy a row from excel which have two space at the starting place

    What might be the reason for the runtime error?. Because It worked perfectly in my Xp machine, whereas when i tried in my remote machine i got the same error message

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Copy a row from excel which have two space at the starting place

    Try:
    Sub copy()
        For Count = 1 To Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
            If Strings.Left(Sheets(1).Range("A" & Count), 1) = " " Then
                Sheets(1).Rows(Count).copy Sheets(2).Cells(Count, 1)
            End If
        Next
    End Sub
    Last edited by ragulduy; 12-04-2013 at 08:03 AM.

+ 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. Starting Browser From A Specific Place
    By Tellm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2013, 08:47 AM
  2. Search a space starting from right.
    By titushanke in forum Excel General
    Replies: 5
    Last Post: 01-26-2007, 10:45 AM
  3. Replies: 0
    Last Post: 02-10-2006, 09:00 AM
  4. Replies: 5
    Last Post: 01-04-2006, 03:46 PM
  5. [SOLVED] removing a space from starting of the text
    By shikha in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-24-2005, 07:05 PM

Tags for this Thread

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