+ Reply to Thread
Results 1 to 3 of 3

Macro for Changing Format

Hybrid View

  1. #1
    Registered User
    Join Date
    07-13-2010
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro for Changing Format

    Hi,

    I have an excel file where some data comes in form of vertical columns. I need to allign data appropriately . Also, if there are junk characters like #NA or spaces in the numeric field or if date field is blank, I need to skip that record.

    Attached is the sample excel file with two tabs - Input and Output.

    I would really appreciate if somebody can help in writing a macro for this.
    Attached Files Attached Files
    Last edited by rylo; 07-14-2010 at 05:58 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro for Changing Format

    Hi

    See how this goes.

    Sub aaa()
      Dim DataSH As Worksheet, OutSH As Worksheet
      Set OutSH = Sheets("Output")
      Set DataSH = Sheets("Input")
      OutSH.Range("A:C").ClearContents
      DataSH.Activate
      For i = 1 To Cells(2, Columns.Count).End(xlToLeft).Column Step 3
        For j = 4 To Cells(Rows.Count, i).End(xlUp).Row
          If Not IsEmpty(Cells(j, i)) And Not IsEmpty(Cells(j, i + 1)) And IsNumeric(Cells(j, i + 1)) Then
            outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
            OutSH.Cells(outrow, 1).Value = Cells(2, i).Value
            OutSH.Cells(outrow, 2).Value = Cells(j, i).Value
            OutSH.Cells(outrow, 3).Value = Cells(j, i + 1).Value
          End If
        Next j
      Next i
      
      OutSH.Rows("1:1").Delete shift:=xlUp
      
    End Sub
    rylo

  3. #3
    Registered User
    Join Date
    07-13-2010
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    {SOLVED} -- Macro for Changing Format

    it worked like a charm...Thanks a lot!!!
    Last edited by raj1985; 07-14-2010 at 05:09 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1