PDA

View Full Version : [SOLVED] Getting values from merged cells



chakalido
08-05-2014, 12:39 AM
Hello! I am having trouble to get values from an other excel workbook that has some merged cells in it. In the DO part of the code, I need to fix that so it takes all the values from merged cells when using offset. I know that with .mergearea we can do that but I'm trying to implement it in the code and I can't fix it. Is there anyone that can help me a little? Thank you very much
(This code is part of a bigger code)



For Each ws In SourceWb.Worksheets

If IsNumeric(Left(ws.name, 3)) Then
Set gCell = ws.Columns("F").Find(what:=numdoc, LookIn:=xlValues, lookat:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, searchformat:=False)
If Not gCell Is Nothing Then
firstAddress = gCell.Address
contador = contador + 1
ColorIndexOfCF = gCell.Interior.ColorIndex
Do

HojaNueva.Cells(F2, 20).Value = gCell.Offset(, 4).Value
HojaNueva.Cells(F2, 21).Value = gCell.Offset(, 5).Value

HojaNueva.Rows(F2).Interior.ColorIndex = ColorIndexOfCF
Set gCell = ws.Columns("F").FindNext(gCell)


Loop While Not gCell Is Nothing And gCell.Address <> firstAddress
End If
End If
Next ws
Set gCell = Nothing
If contador = 0 Then
HojaNueva.Cells(F2, 19).Value = "NUEVO"
End If
End If
End If
End If
Next F1
End With
SourceWb.Close False
MsgBox ("Hay " & F2 - 1 & " Entradas de datos")

Exit Sub

chakalido
08-05-2014, 02:26 AM
Auto solved jaja replace the part of the code for this
HojaNueva.Cells(F2, 20).Value = gCell.Offset(, 4).MergeArea.Value
HojaNueva.Cells(F2, 21).Value = gCell.Offset(, 5).MergeArea.Value