Consulting

Results 1 to 10 of 10

Thread: Solved: Find String and Merge Cells

  1. #1

    Solved: Find String and Merge Cells

    Dear All

    My first posting on this site so please appreciate that I am not that good with vba.

    I have a need to look for repeated (quite numerous) occurrences of the months of the year and the text "YTD" that I receive from a main frame as text in the format mmm yyyy and then merge the cell that has the date/YTD in it with the two cells to the right.

    The dates are not dates in the Excel way but merely text and every month is only 3 characters long plus the 4 digit year.

    So to recap I have Apr 2008 in cell B4 with cells C4 & D4 blankand I want cells B4-D4 to be merged. In addition there will always be a YTD cell with two empty cells to the right that need to be merged.

    I hope that I haven't made what I think is quite a simple problem sound to complicated.

    Many thanks for any help that you can provide

  2. #2
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    can you post a sample workbook?

    will be easier to help you.

  3. #3

    Find String and Merge Cells

    Certainly

    Sheet attached with dummy data but the original has no formulas just pure text and numbers.
    As the year progresses additional months will be included until there are 12 months but there will always be a YTD.

    Thank you for taking the time.

    Danesrood

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Is it necessary to Merge Cells. These can cause problems if further VBA is required. Cente Across Selection can give the same result, without the downside.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    No attachment. Use Manage Attachments in the Go Advanced reply section
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6

    Find String and Merge Cells

    mdmackillop

    Yes centre across will be fine.

    The attachment is there according to Manage Attatchments?

    But if you can search for the strings for the month regardless of 2008 or 2009 etc along with YTD and centre across the three cells I am sure that would be fine.

    Thank you for your interest.

    Danesrood

  7. #7
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    try that:

    [vba]
    Option Explicit
    Sub Formating()

    Dim Rng, c As Range

    Set Rng = ActiveSheet.UsedRange

    For Each c In Rng
    If IsDate(c.Value) Or c.Value = "YTD" Then
    With Range(c, c.Offset(0, 2))
    .HorizontalAlignment = xlCenterAcrossSelection
    .VerticalAlignment = xlCenter
    End With
    End If
    Next c
    End Sub
    [/vba]

  8. #8

    Find String and Merge Cells

    MaximS

    That works a treat thank you so much.

    But what I can't understand is that you are looking for a date but if I try to add a number to the date and change the format so that I can see the days I get a #Value so it's not a date is it?

    In any event it does precisely what I want so again my sincere thanks.

    Danesrood

  9. #9
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    Excel is automaticaly recognizing if given string matches one of Excel default date formats. And MMM YYYY format is perfectly looking like a date for Excel.

  10. #10

    Find String and Merge Cells

    Seems strange but hey it does what I want.

    Again my thanks

Posting Permissions

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