+ Reply to Thread
Results 1 to 3 of 3

Sorting and copying data with VBA Excel

  1. #1
    Registered User
    Join Date
    03-07-2014
    Location
    Varna, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    2

    Sorting and copying data with VBA Excel

    Hello,
    I appeal to you, as after much searching and writing in forums and sites, nobody could help me.

    My question is this:
    I want to sort and copy data by predefined attribute (text) from one Sheet (Sheet2) to another (Sheet3), using a button that is located in Sheet1. Value at which will be sorting is defined by ComboBox.
    ie I have a set of data stored in Sheet2 (village, municipality, district). When I click on the sort in Sheet1, all matches to the specified attribute to be copied together with the entire rows (line) and saved to a specified location on Sheet 3 - for example, the beginning of the record set C3.
    This is the code I used, but I have two problems:
    1. Code is activated only when the button is installed on the data sheet (Sheet2)
    2. Data is written to Sheet3 only cell A1 (gives me an error when I try to change the address of the cell).
    Here's the code:

    Private Sub CommandButton1_Click()
    Dim startRa As Range
    Dim endRa As Range
    Dim DataRowNum As Integer, SheetRowNum As Integer

    Range(„A1″).Select
    Cells.Find(What:=ComboBox1.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False).Activate
    Set startRa = ActiveCell

    Do
    Set endRa = ActiveCell
    Cells.Find(What:=ComboBox1.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False).Activate
    Loop While ActiveCell.Row = endRa.Row + 1

    Rows(startRa.Row & „:“ & endRa.Row).Select

    Selection.Copy Destination:=Sheet3.Range(„a65536″).End(xlUp).Offset(1, 0)

    End Sub


    I would be very grateful if someone help me succeed
    Last edited by pl666; 03-09-2014 at 01:15 PM.

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

    Re: Sorting and copying data with VBA Excel

    Try this. It copies from columns A:Z and not the entire row. You can change that to suit.

    You could not copy an entire row and paste it starting in column C. The entire row won't fit. The last two cells in the row have no place to go.

    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
    Registered User
    Join Date
    03-07-2014
    Location
    Varna, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Sorting and copying data with VBA Excel

    Thank you very much. Code works perfectly. Your help was very useful

+ 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. copying and sorting data in spreadsheet
    By mrjboyle in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-24-2013, 06:35 PM
  2. Copying & Sorting Data from one sheet to another
    By nosikliw in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-15-2013, 12:34 PM
  3. Sorting Data and then copying to new sheet
    By Drew Davis in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-26-2011, 02:52 PM
  4. Copying data from col to col for a sorting job
    By LeonardF in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-12-2009, 04:59 PM
  5. Copying values from other worksheets & sorting data
    By J10 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-28-2009, 04:22 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