Consulting

Results 1 to 8 of 8

Thread: Blank Columns

  1. #1
    VBAX Contributor
    Joined
    May 2010
    Posts
    107
    Location

    Blank Columns

    Hi Friends,

    How to delete the blank columns in all worksheets in an Excel, and how to delete the periods which occurs in the 1st ("A") column using coding.

    Attached file for your reference.

    Regards,
    Rakesh
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Do a Find and Replace on column A, but be sure to copy from one of the cells as they are ellipsis (...) not dots
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    To delete the blank cols

    [vba]

    Public Sub ProcessData()
    Dim Lastcol As Long
    Dim i As Long

    Application.ScreenUpdating = False

    With ActiveSheet

    Lastcol = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column

    For i = Lastcol To 2 Step -1

    If .Cells(3, i).Value = "" Then

    .Columns(i).Delete
    End If
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Contributor
    Joined
    May 2010
    Posts
    107
    Location
    Hi James,

    Thanks for your kind help. Its working fine. But it Deletes only in the Active sheet. How to Delete in all Sheets.

    Thanks,
    Rakesh

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Dim sh as worksheet
    for each sh in sheets
    With sh
    LastCol ' etc.[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Probably best to use

    [vba]

    For Each sh In Activeworkbook.Worksheets
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Contributor
    Joined
    May 2010
    Posts
    107
    Location
    Hi James,

    Where to insert this line?

    For Each sh In Activeworkbook.Worksheet

    Thanks,
    Rakesh

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Dim sh As Worksheet
    Dim Lastcol As Long
    Dim i As Long

    Application.ScreenUpdating = False

    For Each sh In Activeworkbook.Worksheets

    With ActiveSheet

    Lastcol = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column

    For i = Lastcol To 2 Step -1

    If .Cells(3, i).Value = "" Then

    .Columns(i).Delete
    End If
    Next i
    End With
    Next sh

    Application.ScreenUpdating = True
    End Sub [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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