Results 1 to 8 of 8

VBA Merge Help

Threaded View

BriceRandall VBA Merge Help 05-09-2023, 04:55 PM
BriceRandall Re: VBA Merge Help 05-09-2023, 05:31 PM
torachan Re: VBA Merge Help 05-09-2023, 06:47 PM
BriceRandall Re: VBA Merge Help 05-10-2023, 02:48 AM
CheeseSandwich Re: VBA Merge Help 05-10-2023, 02:55 AM
BriceRandall Re: VBA Merge Help 05-10-2023, 03:19 AM
BriceRandall Re: VBA Merge Help 05-10-2023, 03:14 AM
CheeseSandwich Re: VBA Merge Help 05-10-2023, 03:33 AM
  1. #1
    Registered User
    Join Date
    05-09-2023
    Location
    Mississippi, U.S.
    MS-Off Ver
    18.2303.1201.0
    Posts
    5

    VBA Merge Help

    Level II Help.jpg
    Good Day! I am active duty military that runs construction projects for the Navy. I am currently in the process of automating a template while teaching myself VBA at the same time. The file I'm currently working lists my Project's Master Activities on the left and tracks them via 3 rows that have time estimated, time earned, and time expended. Those Columns fall under a bi-weekly reporting periods. Row 6 is the full date (5/9/2023 format) but uses the "ddd" display to show just the day. Rows 4 and 5 are =TEXT(G$6,"mmmm") and supposed to merge together to display the month. The goal is that the user can change G6s date, that trickles down the columns with a +14 days for the bi-weekly reporting. (that already works) then the VBA automatically unmerges G4:AF5 (a full year), autofills the range with =TEXT(G$6,"mmmm"), then it runs a merge code that should merge all similar valued cells together. However, where the code currently sits it only merges similar cells across rows 4 and 5, but does not merge G4:G5, or J4:L5 for November for example. I have tried running the merge code a second time but that runs into errors once added. Any help with this would be very much appreciated!
    Code:

    Private Sub Worksheet_Change(ByVal Target As Range)

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    If Target.Address = "$G$6" Then

    Range("G4:AF5").Select
    Selection.UnMerge
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
    End With
    With Selection.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
    End With
    Range("G4").Select
    Selection.AutoFill Destination:=Range("G4:AF4"), Type:=xlFillDefault
    Range("G4:AF4").Select
    Range("G5").Select
    Selection.AutoFill Destination:=Range("G5:AF5"), Type:=xlFillDefault
    Range("G5:AF5").Select
    End If

    Dim rng As Range, cell As Range, mergedRange As Range
    Set rng = Range("G4:AF5")

    For Each cell In rng
    If cell.Value <> "" And cell.Value = cell.Offset(0, 1).Value Then
    If mergedRange Is Nothing Then
    Set mergedRange = cell
    End If
    Set mergedRange = Union(mergedRange, cell.Offset(0, 1))
    Else
    If Not mergedRange Is Nothing Then
    mergedRange.Merge
    mergedRange.HorizontalAlignment = xlCenter
    Set mergedRange = Nothing
    End If
    End If
    Next cell

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

    End Sub
    Last edited by BriceRandall; 05-10-2023 at 03:20 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 11-15-2018, 10:54 PM
  2. Mail Merge Directory - Creating merge with multiple lines
    By tiggynook in forum Excel General
    Replies: 3
    Last Post: 05-03-2017, 03:00 PM
  3. Replies: 0
    Last Post: 06-24-2015, 02:34 AM
  4. Email merge from excel merge file using pre-saved word template
    By d_max_c in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2014, 12:33 PM
  5. Replies: 2
    Last Post: 01-22-2013, 11:37 AM
  6. Email Merge with variable merge records break by client level
    By sss047 in forum Word Formatting & General
    Replies: 0
    Last Post: 04-15-2011, 04:25 AM
  7. Replies: 0
    Last Post: 04-21-2006, 03:40 PM

Tags for this Thread

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