Consulting

Results 1 to 4 of 4

Thread: Solved: copy ranges (tables) separated for separate tabs

  1. #1
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location

    Solved: copy ranges (tables) separated for separate tabs

    Hi.
    how to find small tables and copy each for a guide?

    I created the tabs manually, the code has to pick up the tab master data, and create tebela 1 for the first intervalor with data, and so
    Attached Files Attached Files

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi marreco.
    try this.
    it assumes tables are seperated with at least 1 blank row.

    [VBA]
    Sub FindMultipleInstancesAddWsCopyFoundCellCurrentRegion()
    'adopted from: http://www.cpearson.com/excel/FindAll.aspx

    Dim LookUpRng As Range, LastCell As Range, FoundCell As Range
    Dim FirstAddress As String, SearchStr As String, TabName As String

    SearchStr = "TABELA"

    Set LookUpRng = Worksheets("Master").UsedRange
    With LookUpRng
    Set LastCell = .Cells(.Cells.Count)
    Set FoundCell = .Find(What:=SearchStr, _
    after:=LastCell, _
    LookIn:=xlValues, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False, _
    SearchFormat:=False)
    End With

    If Not FoundCell Is Nothing Then
    FirstAddress = FoundCell.Address
    Do
    TabName = Mid(FoundCell, InStr(1, FoundCell, SearchStr))
    Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = TabName
    FoundCell.CurrentRegion.Copy ActiveSheet.Cells(1, 1)
    Set FoundCell = LookUpRng.FindNext(FoundCell)
    Loop Until FoundCell.Address = FirstAddress
    End If

    End Sub
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.

    I'm very glad you help me!

    very perfect!!

    thank you very much!!

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.

    and thanks for marking the thread as "solved".
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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