Results 1 to 18 of 18

VBA Macro: Copy and Paste Specific Row Range based on the Specific Value in a Cell.

Threaded View

  1. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Macro: Copy and Paste Specific Row Range based on the Specific Value in a Cell.

    OK, added some new features.

    1) The DAILYAVAILABILITY Macro now looks at cell C1 on each sheet from which it is called to see what "week #" you have selected to display.
    2) C1 has a drop down listing all the Week #s currently contained on the Availability sheet
    3) The ThisWorkbook module now has a "SheetActivate" macro that updates the drop down list in realtime anytime you activate a sheet. So the drop down will always be current for the sheet you are reviewing.
    4) If the current value of C1 is NOT a week that is found on the Availability sheet any longer, the sheet automatically run the update macro to display the first week it does find. After that, you can select any other week from the C1 drop down and UPDATE it again.

    ThisWorkbook code:
    Option Explicit
    
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Dim buf As String, cell As Range
    
    If Sh.Name <> "Availability" Then
        With Sheets("Availability")
            For Each cell In .Rows(1).SpecialCells(xlConstants)
                If cell.Value <> "" Then
                    If buf = "" Then
                        buf = cell.Value
                    Else
                        buf = buf & "," & cell.Value
                    End If
                End If
            Next cell
        End With
        If buf <> "" Then
            With Sh.Range("C1").Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=buf
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
            End With
            Range("C1").Activate
            If InStr(buf, Range("C1").Value) = 0 Then
                If InStr(buf, ",") = 0 Then
                    Range("C1") = buf
                Else
                    Range("C1") = Left(buf, InStr(buf, ",") - 1)
                End If
                Call Module1.DailyAvailability
            End If
        End If
    End If
    
    End Sub
    Updated DailyAvailibilty code in module1:
    Option Explicit
    
    Sub DailyAvailability()
    Dim wsMAIN As Worksheet, wsME As Worksheet, meFIND As Range, LR As Long
    Dim wkFIND As Range
    
    Set wsMAIN = Sheets("Availability")             'the sheet with the hours
    Set wsME = ActiveSheet                          'the currrent sheet to update
    
    On Error Resume Next
    With wsMAIN
        Set wkFIND = wsMAIN.Rows(1).Find(wsME.Range("C1").Text, LookIn:=xlValues, LookAt:=xlWhole).MergeArea.Cells
        LR = .Range("A" & .Rows.Count).End(xlUp).Row        'find the last row of availability date
        Set meFIND = Intersect(.Range(wkFIND.Address).EntireColumn, .Rows(2)).Find(wsME.Name, _
                       LookIn:=xlValues, LookAt:=xlWhole)   'find the current day
        If Not meFIND Is Nothing Then                       'if sheetname/day is found, proceed
            wsME.UsedRange.Offset(1).Clear                  'clear prior info
            .AutoFilterMode = False                         'remove prior filters
            .Rows(3).AutoFilter meFIND.Column, "Active"     'filter daily column for "active" only
            .Range("A2:F" & LR).Copy wsME.Range("A2")       'copy name info, then copy hours
            .Range(.Cells(2, meFIND.Column - 2), .Cells(LR, meFIND.Column - 1)).Copy wsME.Range("G2")
            .AutoFilterMode = False
            Application.CutCopyMode = False
            wsME.Columns.AutoFit
        End If
    End With
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. macro to copy range hidden paste in a specific location
    By graiggoriz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2014, 11:27 AM
  2. [SOLVED] Macro to copy specific data from one WB to specific cells in another WB based on specific
    By d_rose in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2014, 11:05 AM
  3. Macro to copy specific line from text file and paste into specific cell in excel
    By keeneye in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-05-2013, 10:35 AM
  4. Copy and paste specific range to date specific range in alternate sheet
    By alanalmarza in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2013, 08:29 AM
  5. macro to copy a range of worksheets based on cell entry and rename specific sheets
    By Lbischoff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2012, 12:13 PM
  6. HELP! Macro to Copy specific cells from one sheet to another based on specific criteria
    By atriscritti in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-11-2012, 11:05 AM
  7. [SOLVED] Macro - Copy and Paste to a Specific Row based on the input in a cell
    By usc1382 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-22-2012, 05:05 PM
  8. Copy & paste specific column based on cell reference
    By ccsmith in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2011, 03:59 AM

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