+ Reply to Thread
Results 1 to 4 of 4

Delete 1 to 8 rows. Do text to columns to specific columns.

  1. #1
    Registered User
    Join Date
    03-01-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Delete 1 to 8 rows. Do text to columns to specific columns.

    Open the file in the path. Do text to columns to the entire sheet. Delete the Range (1 to 8 rows). Insert value zero in columns G1, I1, L1, N1, P1 only if they are balnk. Now do text to columns to Column G, L, N & P. Save the file as

    Need macro for this. Please help.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Delete 1 to 8 rows. Do text to columns to specific columns.

    Try turning on the macro recorder and manually carrying out the steps you've outlined.

    That should generate code that can be adapted to do exactly what you want.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-01-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Delete 1 to 8 rows. Do text to columns to specific columns.

    I am getting struck at "only if they are blank". Can you help on this?

  4. #4
    Registered User
    Join Date
    03-01-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Delete 1 to 8 rows. Do text to columns to specific columns.

    This is how I could create. Any suggestions for this would be helpful.

    Sub Macro()
    '
    ' Macro1 Macro

    Dim Filter As String, Title As String
    Dim FilterIndex As Integer
    Dim Filename As Variant
    ' File filters
    Filter = "Excel Files (*.xls),*.xls," & _
    "Text Files (*.txt),*.txt," & _
    "All Files (*.*),*.*"
    ' Default Filter to *.*
    FilterIndex = 3
    ' Set Dialog Caption
    Title = "Select a File to Open"
    ' Select Start Drive & Path
    ChDrive ("D")
    ChDir ("D:\Documents and Settings")
    With Application
    ' Set File Name to selected File
    Filename = .GetOpenFilename(Filter, FilterIndex, Title)
    ' Reset Start Drive/Path
    ChDrive (Left(.DefaultFilePath, 1))
    ChDir (.DefaultFilePath)
    End With
    ' Exit on Cancel
    If Filename = False Then
    MsgBox "No file was selected."
    Exit Sub
    End If
    ' Open File
    Workbooks.Open Filename
    MsgBox Filename, vbInformation, "File Opened" ' This can be removed


    Rows("1:12").Select
    Selection.Delete Shift:=xlUp
    Cells.Select
    Cells.EntireColumn.AutoFit

    Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 2), TrailingMinusNumbers:=True


    Range("G2").Select
    If Selection.Value = "" Then
    ActiveCell.FormulaR1C1 = "0"
    End If

    Range("I2").Select
    If Selection.Value = "" Then
    ActiveCell.FormulaR1C1 = "0"
    End If

    Range("L2").Select
    If Selection.Value = "" Then
    ActiveCell.FormulaR1C1 = "0"
    End If

    Range("M2").Select
    If Selection.Value = "" Then
    ActiveCell.FormulaR1C1 = "0"
    End If

    Range("N2").Select
    If Selection.Value = "" Then
    ActiveCell.FormulaR1C1 = "0"
    End If

    Range("P2").Select
    If Selection.Value = "" Then
    ActiveCell.FormulaR1C1 = "0"
    End If


    Columns("G:G").Select
    Selection.TextToColumns Destination:=Range("G1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 2), TrailingMinusNumbers:=True

    Columns("L:L").Select
    Selection.TextToColumns Destination:=Range("L1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 2), TrailingMinusNumbers:=True

    Columns("M:M").Select
    Selection.TextToColumns Destination:=Range("M1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 2), TrailingMinusNumbers:=True

    Columns("N:N").Select
    Selection.TextToColumns Destination:=Range("N1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 2), TrailingMinusNumbers:=True

    Columns("P:P").Select
    Selection.TextToColumns Destination:=Range("P1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 2), TrailingMinusNumbers:=True

    Columns("R:R").Select
    Selection.TextToColumns Destination:=Range("R1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 2), TrailingMinusNumbers:=True

    Range("R1").Select
    Selection.End(xlToLeft).Select

    ChDir "D:\Documents and Settings\Book2.xlsx"
    ActiveWorkbook.SaveAs Filename:="CABC" & " " & Range("Q2").Value & " " & Range("u2").Value & " " & Range("W2").Value & ".xls"


    End Sub

+ 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