Results 1 to 4 of 4

Thread: Fetch values from merged cells in macro

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    24
    Rep Power
    0

    Fetch values from merged cells in macro

    Hi Team,

    As per my attached template I will have entries in column Y in merged cells. Those merged cell values belong to the same row of sample 2.
    I am working on a development of macro where from these entries in excel I will fetch multiple csv files to upload in oracle tables through my web application.

    Csv extraction all is working fine with the help of this forum. Now I need to fetch the values from this merged cell and in csv i need to put these values in two separate rows . For eg. refer attached sheet with filename sample_csv.

    Also there is a single row space between each sample in the excel named TEMPLATE_EXCEL, when I extract csv I need to ignore these row spaces and put the entry in csv without any row spaces so please do help me with this also

    Kindly help me with the code for both the need

    Thanks in advance

    Regards
    Dhivya
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Oct 2013
    Posts
    24
    Rep Power
    0
    Quote Originally Posted by dhivya.enjoy View Post
    Hi Team,

    As per my attached template I will have entries in column Y in merged cells. Those merged cell values belong to the same row of sample 2.
    I am working on a development of macro where from these entries in excel I will fetch multiple csv files to upload in oracle tables through my web application.

    Csv extraction all is working fine with the help of this forum. Now I need to fetch the values from this merged cell and in csv i need to put these values in two separate rows . For eg. refer attached sheet with filename sample_csv.

    Also there is a single row space between each sample in the excel named TEMPLATE_EXCEL, when I extract csv I need to ignore these row spaces and put the entry in csv without any row spaces so please do help me with this also

    Kindly help me with the code for both the need

    Thanks in advance

    Regards
    Dhivya
    Hi Team,

    Any ideas for my query.

  3. #3
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    try this

    Code:
    Sub kTest()
        
        Dim k, i As Long, j As Long, a() As String, n As Long
        Dim wbkNew As Workbook, r As Range, c As Long
        
        With Worksheets("Sheet1")
            On Error Resume Next
            With .Range("a2:ac" & .UsedRange.Rows.Count)
                Set r = .Columns(1).SpecialCells(xlCellTypeConstants, 23)
                c = .Columns.Count
            End With
        End With
        If Not r Is Nothing Then
            For i = 1 To r.Areas.Count
                With r.Areas(i).Resize(, c)
                    Debug.Print .Address
                    .UnMerge
                    .SpecialCells(4).FormulaR1C1 = "=r[-1]c"
                    k = .Value2
                End With
                For j = 1 To UBound(k, 1)
                    n = n + 1
                    ReDim Preserve a(1 To n)
                    a(n) = Join(Application.Index(k, j, 0), "|")
                Next
            Next
            If n Then
                Set wbkNew = Workbooks.Add(xlWBATWorksheet)
                With wbkNew.Worksheets(1)
                    .Range("a1").Resize(n) = Application.Transpose(a)
                    .Range("a1").Resize(n).TextToColumns .Range("A1"), 1, Other:=True, OtherChar:="|"
                    .Range("i1").Resize(n).TextToColumns .Range("i1"), 1, , FieldInfo:=Array(1, 5)
                    .Range("j1").Resize(n).TextToColumns .Range("j1"), 1, , FieldInfo:=Array(1, 5)
                End With
                wbkNew.SaveAs ThisWorkbook.Path & "\" & "CSVFileName.CSV", 6
                wbkNew.Close 0
                Set wbkNew = Nothing
            End If
        End If
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  4. #4
    Member
    Join Date
    Nov 2011
    Posts
    41
    Rep Power
    0
    let say you have a merge cells A1:C1 then for extracting the data from this you can code it like this.

    Code:
    range("A1:C1").areas(1).cells(1,1)

    Regards
    Prince
    Last edited by bakerman; 11-20-2013 at 03:27 PM. Reason: codetags added

Similar Threads

  1. Replies: 10
    Last Post: 11-21-2013, 04:41 PM
  2. Macro to fetch csv file and edit the file
    By dhivya.enjoy in forum Excel Help
    Replies: 6
    Last Post: 10-23-2013, 01:00 PM
  3. Macro to fetch csv files
    By dhivya.enjoy in forum Excel Help
    Replies: 2
    Last Post: 10-21-2013, 05:44 PM
  4. Fetch multiple values based on criteria
    By Lucero in forum Excel Help
    Replies: 8
    Last Post: 04-07-2012, 12:35 PM
  5. Find Merged Cells VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 4
    Last Post: 02-25-2012, 03:07 PM

Posting Permissions

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