Consulting

Results 1 to 2 of 2

Thread: Getting values from merged cells

  1. #1
    VBAX Regular
    Joined
    Jul 2014
    Location
    Barcelona
    Posts
    24

    Getting values from merged cells

    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

  2. #2
    VBAX Regular
    Joined
    Jul 2014
    Location
    Barcelona
    Posts
    24
    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

Tags for this Thread

Posting Permissions

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