Consulting

Results 1 to 4 of 4

Thread: Coding Error :(

  1. #1
    VBAX Newbie
    Joined
    Aug 2005
    Posts
    3
    Location

    Coding Error :(

    Below is the code I am working with. The line " If Month(Cells(9, curcolumn).Value) = Month(Cells(9, columncompare).Value) Then" is giving me a run time 13 error (type mismatch)... Anyone have any ideas on how I can fix that? Thanks!

    Sub datemerger()
    Dim curcolumn, columncompare As Integer
    curcolumn = 9
    columncompare = curcolumn + 1
    Do While (Len(Sheets("Part").Cells(9, curcolumn).Value) > 0)
        If Month(Cells(9, curcolumn).Value) = Month(Cells(9, columncompare).Value) Then
            Range(Cells(9, curcolumn), Cells(9, columncompare)).Merge
            With Selection
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlBottom
                .WrapText = True
                .Orientation = 0
                .AddIndent = False
                .IndentLevel = 0
                .ShrinkToFit = False
                .ReadingOrder = xlContext
            End With
            'curcolumn = curcolumn + 1
        Else
            curcolumn = columncompare
        End If
        columncompare = columncompare + 1
        Application.DisplayAlerts = False
    Loop
    Application.DisplayAlerts = True
    End Sub
    Last edited by Aussiebear; 04-27-2023 at 07:49 PM. Reason: Adjusted the code tags

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    First question would be do you have a sheet named "Part"
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    At that time, what is columncompare and curcolumn values? What is housed in those cells?

    Sounds like an error you would receive if the cell(s) specified had an invalid address. Loops can be a pain for things like that.

  4. #4
    VBAX Newbie
    Joined
    Aug 2005
    Posts
    3
    Location
    ok.. Thanks both of you! There was an error in one of the cells so I fixed it and it works.....kind of. there is not an error anymore but now it doesnt quiet do what I want it to do. The dates are inputed in the cells as 5/1/05 and I want it to merge any cells that have the same month. For some reason, it isnt doing that. I don't know for sure why because I thought that the Month() function would do that.... any ideas? Thanks again!

Posting Permissions

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