+ Reply to Thread
Results 1 to 12 of 12

how to programatically do lot of steps

Hybrid View

  1. #1
    Registered User
    Join Date
    12-21-2010
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    73

    Thumbs up how to programatically do lot of steps

    Hi All,

    I have tons of data arranged in spreadsheet. And i need to do various steps to do work on it. I wonder if these steps can be programed in Excel so that they can be executed with a click of a button.

    Here is what i do manually.

    1. goto column #F.
    2. This column contains a text string.
    3. Select the entire ROW if the first character of the text string is 'A'.
    4. Copy all the selected ROWs and PASTE them in a new spreadsheet.

    Any idea if this can be programmed ?

    Any help would be greatly appreciated.

    -naeemdotcom
    Last edited by naeemdotcom; 01-10-2011 at 02:44 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how to programatically do lot of steps

    Have you tried this

    Apply a filter to your sheet

    With column F

    Text filters > Begins with

    Show Rows Where:
    Begins with:= a

    Select the "or" radio button
    then in the next 2 fields
    Begins with:= A

    Select all the resultant rows
    Copy and Paste to new sheet
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Registered User
    Join Date
    12-21-2010
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: how to programatically do lot of steps

    Thanks for your reply.

    Pls. tell me what do you mean by "Apply filter to your sheet"... i tried it as this that i press the filter button but nothing happens. Me using Excel 2007.


    Quote Originally Posted by Marcol View Post
    Have you tried this

    Apply a filter to your sheet

    With column F

    Text filters > Begins with

    Show Rows Where:
    Begins with:= a

    Select the "or" radio button
    then in the next 2 fields
    Begins with:= A

    Select all the resultant rows
    Copy and Paste to new sheet

  4. #4
    Registered User
    Join Date
    12-21-2010
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: how to programatically do lot of steps

    Once again thanks for your reply.

    Pls. help me to do these kind of steps programatically. I am more interested in VBA code for this.


    Quote Originally Posted by Marcol View Post
    Have you tried this

    Apply a filter to your sheet

    With column F

    Text filters > Begins with

    Show Rows Where:
    Begins with:= a

    Select the "or" radio button
    then in the next 2 fields
    Begins with:= A

    Select all the resultant rows
    Copy and Paste to new sheet

  5. #5
    Registered User
    Join Date
    12-21-2010
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: how to programatically do lot of steps

    Also i would appreciate if anyone can guide me to some good tutorial on learning the excel programming.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: how to programatically do lot of steps

    Why not respond to the person who is trying to help you?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: how to programatically do lot of steps

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  8. #8
    Registered User
    Join Date
    12-21-2010
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: how to programatically do lot of steps

    Thanks for your reply. Here is a sample workbook.

    I am interested in parsing out data from this type of sheets in following steps.

    1. Delete all ROWS in which the column AB is empty.
    2. Select all ROWS in which the first letter of the text in column AB is "A".
    3. Copy those ROWS and paste into separate sheet.



    Quote Originally Posted by royUK View Post
    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Attached Files Attached Files

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how to programatically do lot of steps

    Try this before you think of macros.

    1/, Highlight the columns you need to copy

    2/. Click on the Tab "Data" in the ribbon.

    3/. Click on Filter.

    4/. Click on the arrowhead in the right side of column F

    5/. In the pop-up panel go to Text Filters > Begins With....

    6/. In the resulting Dialogue box you will see
    Show Rows Where:
    begins with, in the box to the right type the single letter a

    7/. Press Okay

    8/. Select all the resultant rows, or the area you need
    Copy and Paste to new sheet

    9/. Remove the filter.


    If you really need a macro for this, try recording a macro while following the above steps.

  10. #10
    Registered User
    Join Date
    07-27-2010
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: how to programatically do lot of steps

    Hi,

    Try the following:

    Public Sub CopyRows()
        Dim lRow As Long
        Dim lLastRow As Long
        Dim lTargetRow As Long
        Dim wksData As Excel.Worksheet ' data sheet
        Dim wksTarget As Excel.Worksheet ' target sheet
        Const iCOL As Integer = 6 ' column F
        Const lFIRST_ROW As Integer = 2 ' first data row (change as appropriate)
        
        Set wksData = ThisWorkbook.Sheets(1) ' change as appropriate
        Set wksTarget = ThisWorkbook.Sheets.Add
        
        With wksData
        
            ' get the last used row
            lLastRow = .Cells(.Rows.Count, iCOL).End(xlUp).Row
            
            ' loop through used rows
            lTargetRow = 1
            For lRow = lFIRST_ROW To lLastRow
                
                ' check whether the cell value starts with "a" and paste to the
                ' target row on the target sheet if so
                If Left$(Trim$(.Cells(lRow, iCOL)), 1) = "a" Then
                    .Rows(lRow).EntireRow.Copy
                    wksTarget.Cells(lTargetRow, 1).PasteSpecial , Paste:=xlAll
                    lTargetRow = lTargetRow + 1
                End If
                
            Next
        
        End With
        
        Set wksData = Nothing
        Set wksTarget = Nothing
        
    End Sub

    Thanks,
    Dom

  11. #11
    Registered User
    Join Date
    12-21-2010
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: how to programatically do lot of steps

    Thanks a lot DOM for your code. It is very helpfull. Would you be kind enough to write comments in each line of your code to explain what is it doing? It will greatly help me in the understanding of the code working also.

    Thanks again.



    Quote Originally Posted by Dom83 View Post
    Hi,

    Try the following:

    Public Sub CopyRows()
        Dim lRow As Long
        Dim lLastRow As Long
        Dim lTargetRow As Long
        Dim wksData As Excel.Worksheet ' data sheet
        Dim wksTarget As Excel.Worksheet ' target sheet
        Const iCOL As Integer = 6 ' column F
        Const lFIRST_ROW As Integer = 2 ' first data row (change as appropriate)
        
        Set wksData = ThisWorkbook.Sheets(1) ' change as appropriate
        Set wksTarget = ThisWorkbook.Sheets.Add
        
        With wksData
        
            ' get the last used row
            lLastRow = .Cells(.Rows.Count, iCOL).End(xlUp).Row
            
            ' loop through used rows
            lTargetRow = 1
            For lRow = lFIRST_ROW To lLastRow
                
                ' check whether the cell value starts with "a" and paste to the
                ' target row on the target sheet if so
                If Left$(Trim$(.Cells(lRow, iCOL)), 1) = "a" Then
                    .Rows(lRow).EntireRow.Copy
                    wksTarget.Cells(lTargetRow, 1).PasteSpecial , Paste:=xlAll
                    lTargetRow = lTargetRow + 1
                End If
                
            Next
        
        End With
        
        Set wksData = Nothing
        Set wksTarget = Nothing
        
    End Sub

    Thanks,
    Dom

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: how to programatically do lot of steps

    Please don't quote whole posts in your replies

+ 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