+ Reply to Thread
Results 1 to 7 of 7

Improve code for sending info to multiple sheet

Hybrid View

  1. #1
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Improve code for sending info to multiple sheet

    Hi all,

    I use this code for sending info to a specific sheet, I'd like to have one code for multiple sheets instead of using code for each each sheet.
    Could you improve this code, please?
    Sub Tstocc65()
    '****start 65
    Dim Tstocc As Range, _
            Found   As Variant, _
            NextRow As Long
    
        Sheets("FCI-65").Range("a55:e64") = "" '55-64
        
        For Each Tstocc In Sheets("MEL").Range("A70:A90")
            With Sheets("FCI-65").Range("D26:G29")
                Set Found = .Find(Trim(Tstocc.Text))
                If Not Found Is Nothing Then
                    Sheets("FCI-65").Range("a" & (55 + NextRow)).Value = Tstocc.Value
                    Sheets("FCI-65").Range("E" & (55 + NextRow)).Value = Tstocc.offset(0, 1).Value
                    NextRow = NextRow + 1
                End If
            End With
        Next Tstocc
    '*end 
    End Sub
    other sheets: FCI-65, FCI-66, FCI-313, FCI-315, ...Chrt8, Chrt9, Chrt11...
    Thank you very much for your help.
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Improve code for sending info to multiple sheet

    Try this.

    Sub Tstocc65()
    '****start 65
    Dim Tstocc As Range, _
            Found   As Variant, _
            NextRow As Long
            Dim arrSheets, c As Long
            
            
            arrSheets = Array("FCI-65", "FCI-66", "FCI-313", "FCI-315", "Chrt8", "Chrt9", "Chrt11")
    For c = LBound(arrSheets) To UBound(arrSheets)
        Sheets(arrSheets(c)).Range("a55:e64") = "" '55-64
        
        For Each Tstocc In Sheets("MEL").Range("A70:A90")
            With Sheets(arrSheets(c)).Range("D26:G29")
                Set Found = .Find(Trim(Tstocc.Text))
                If Not Found Is Nothing Then
                    Sheets(arrSheets(c)).Range("a" & (55 + NextRow)).Value = Tstocc.Value
                    Sheets(arrSheets(c)).Range("E" & (55 + NextRow)).Value = Tstocc.Offset(0, 1).Value
                    NextRow = NextRow + 1
                End If
            End With
        Next Tstocc
        Next c
    '*end
    End Sub
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,637

    Re: Improve code for sending info to multiple sheet

    Try this (didn't test it).

    Sub Tstocc65()
    
    '****start 65
    Dim ws As Worksheet
    Dim Tstocc As Range, _
            Found   As Variant, _
            NextRow As Long
    
    
     For Each ws In ThisWorkbook.Worksheets
        ws.Range("a55:e64") = "" '55-64
    
        if ws.Name <> "MEL" then
        For Each Tstocc In Sheets("MEL").Range("A70:A90")
            With ws.Range("D26:G29")
                Set Found = .Find(Trim(Tstocc.Text))
                If Not Found Is Nothing Then
                    ws.Range("a" & (55 + NextRow)).Value = Tstocc.Value
                    ws.Range("E" & (55 + NextRow)).Value = Tstocc.offset(0, 1).Value
                    NextRow = NextRow + 1
                End If
            End With
        Next Tstocc
       End if
    Next ws
    '*end 
    End Sub

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Improve code for sending info to multiple sheet

    Here's my attempt:

    Option Explicit
    Sub Tstocc65()
        '****start 65
        Dim Tstocc As Range, _
            Found As Variant, _
            NextRow As Long, _
            varMySheet As Variant
            
        Application.ScreenUpdating = False
            
        For Each varMySheet In Array("FCI-65", "FCI-66", "FCI-313", "FCI-315", "Chrt8", "Chrt9", "Chrt11")
    
            Sheets(varMySheet).Range("A55:E64") = "" '55-64
        
            For Each Tstocc In Sheets("MEL").Range("A70:A90")
                With Sheets(varMySheet).Range("D26:G29")
                    Set Found = .Find(Trim(Tstocc.Text))
                    If Not Found Is Nothing Then
                        Sheets(varMySheet).Range("A" & (55 + NextRow)).Value = Tstocc.Value
                        Sheets(varMySheet).Range("E" & (55 + NextRow)).Value = Tstocc.Offset(0, 1).Value
                        NextRow = NextRow + 1
                    End If
                End With
            Next Tstocc
        
        Next varMySheet
        '*end
    
        Application.ScreenUpdating = True
        
    End Sub
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  5. #5
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Improve code for sending info to multiple sheet

    Hi,
    Skywriter, Zbor and Trebor76 thank you very much for your time and help!
    I really appreciate!

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,637

    Re: Improve code for sending info to multiple sheet

    So what approach worked for you that other users can find solution for them

  7. #7
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Improve code for sending info to multiple sheet

    Hi zbor, all of them!

+ 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. 'sending' multiple boxes to another sheet by 1 click
    By joseph_pat in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-21-2015, 11:04 AM
  2. VBA Code for Multiple criteria auto Filter & sending the mails based on that
    By Rajveer1981 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2012, 01:37 PM
  3. Sheet code to copy & paste a new row of Info to another sheet
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-23-2012, 05:31 PM
  4. Replies: 0
    Last Post: 07-11-2011, 07:10 PM
  5. Code fore Sending Multiple Reports to PrintPreview Window
    By DaniilK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2009, 08:28 PM
  6. Using code to email a sheet but need to strip the code before sending
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-05-2009, 01:44 AM
  7. Sending Info
    By jsnider in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-15-2005, 04:05 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