PDA

View Full Version : [SOLVED:] Coding Error :(



kmjones
08-02-2005, 08:57 AM
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

lucas
08-02-2005, 09:44 AM
First question would be do you have a sheet named "Part"

Zack Barresse
08-02-2005, 10:02 AM
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.

kmjones
08-02-2005, 11:13 AM
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!:hi: