Results 1 to 11 of 11

macro to split data to respective columns not working as expected

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    macro to split data to respective columns not working as expected

    I have column A which has a set of data which needs to be split to their respective headers column B /C D.

    Row1 represents the headers.

    In applying 3 different macros with same output,not giving expected results

    1 first giving compile error variable not defined.

    
    Sub split()
    Dim lr As Long
    Dim myrange As Range, cell As Range
    Dim ws As Worksheet
    
    Set ws = Sheets("Sheet1")
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    
    Set myrange = Range("A2:A" & lr)
    Cells(1, 3) = "Tariff No": Cells(1, 4) = "Description": Cells(1, 5) = "Origin"
    For Each cell In myrange
        txt = cell.Text
        cell.Offset(, 2) = Left(txt, 8)
        cell.Offset(, 3) = Mid(txt, 10, Len(txt) - 18)
        cell.Offset(, 4) = Left(Right(txt, 8), 2)
    Next
    Range("C1:E" & lr).Columns.AutoFit
    End Sub


    the second macro giving invalid procedure callor argument rin time error 5

    Results(R, 2) = Trim(Mid(Data(R, 1), 9, Len(Data(R, 1)) - 16))

    Sub SplitTariffData()
      Dim R As Long, Data As Variant, Results As Variant
      Data = Range("A2", Cells(Rows.Count, "A").End(xlUp))
      ReDim Results(1 To UBound(Data), 1 To 3)
      For R = 1 To UBound(Data)
        Results(R, 1) = Format(Left(Data(R, 1), 8), "00000000")
        Results(R, 2) = Trim(Mid(Data(R, 1), 9, Len(Data(R, 1)) - 16))
        Results(R, 3) = Left(Right(Data(R, 1), 8), 2)
      Next
      Range("C2").Resize(UBound(Results)).NumberFormat = "@"
      Range("C2").Resize(UBound(Results), 3) = Results
    End Sub
    3 rd macro split data incorrectly


    
    Sub SplitIt()
      With Range("A2", Range("A" & Rows.Count).End(xlUp))
        .Offset(, 2).Value = Evaluate("if(row(),""'"" & left(" & .Address & ",8),"""")")
        .Offset(, 3).Value = Evaluate("if(row(),mid(" & .Address & ",10,len(" & .Address & ")-18),"""")")
        .Offset(, 4).Value = Evaluate("if(row(),left(right(" & .Address & ",8),2),"""")")
      End With
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA to split respective multiline from 3 columns
    By chilli16 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-30-2018, 11:14 AM
  2. [SOLVED] macro split specific data to respective columns but should not exceed 32 characters
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2018, 02:24 PM
  3. Formula to split data to their respective columns
    By JEAN1972 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-06-2018, 06:42 AM
  4. [SOLVED] vba split data in respective columns based on unique list sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-29-2017, 02:40 PM
  5. [SOLVED] formula to split data in respective columns
    By JEAN1972 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-06-2017, 02:21 PM
  6. [SOLVED] formula to split data to their respective columns
    By JEAN1972 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-16-2016, 11:50 AM
  7. [SOLVED] Autofitting of columns not working as expected
    By Ezzard in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-12-2015, 07:37 AM

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