Consulting

Results 1 to 10 of 10

Thread: vba code for remove blank cells

  1. #1
    VBAX Regular
    Joined
    Apr 2013
    Posts
    14
    Location

    vba code for remove blank cells

    I want remove blank cells column a and show result in column b
    please give me a vba code
    for example
    remove blank.jpg

  2. #2
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    Try this:

    Sub dural()
    Dim N As Long, NN As Long, K As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    K = 1
    For NN = 1 To N
        If Cells(NN, 1) <> "" Then
            Cells(K, 2) = Cells(NN, 1)
            K = K + 1
        End If
    Next
    End Sub
    Last edited by Aussiebear; 01-21-2023 at 03:25 AM. Reason: Adjusted code tags
    Have a Great Day!

  3. #3
    VBAX Regular HaHoBe's Avatar
    Joined
    Aug 2004
    Location
    Hamburg
    Posts
    89
    Location
    Hi, abbccc,

    if the shown are values (no formulas) you may shorten the loop to only those cells with values like

    Sub abbccc_2()
        Dim rngCell As Range
        Dim lngTarg As Long
        lngTarg = 1
        For Each rngCell In Range("A:A").SpecialCells(xlCellTypeConstants, 23)
            Cells(lngTarg, 2) = rngCell
            lngTarg = lngTarg + 1
        Next rngCell
    End Sub
    Ciao,
    Holger
    Last edited by Aussiebear; 01-21-2023 at 03:24 AM. Reason: Adjusted code tags

  4. #4
    VBAX Regular
    Joined
    Apr 2013
    Posts
    14
    Location
    Thank you HaHoBe
    Thank you GarysStudent

  5. #5
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Or non-looper [frequently shown by snb]
    Option Explicit
    Public Sub GetNonBlanks()
    Dim r As Range
    Dim v As Variant
    Set r = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    v = Filter(Application.Transpose(Evaluate("=IF(" & r.Address & "<>""""," & r.Address & ",""~"")")), "~", False)
    Range("B1").Resize(UBound(v) + 1, 1).Value = Application.Transpose(v)
    End Sub
    Last edited by Aussiebear; 01-21-2023 at 03:24 AM. Reason: Adjusted code tags
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    no error checking and as is will only work with constant cells but both could easily be added

    Sub test()
        Call Columns("A:A").SpecialCells(xlCellTypeConstants, 23).Copy(Range("B1"))
        Application.CutCopyMode = False
    End Sub

    Paul
    Last edited by Aussiebear; 01-21-2023 at 03:23 AM. Reason: Adjusted code tags

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Sub M_snb002()
    With Columns(1)
    .AutoFilter 1, "<>"
    .Cut Cells(1, 2)
    .AutoFilter
    End With
    End Sub
    or

    Sub M_snb003()
    Columns(1).SpecialCells(4).EntireRow.Delete
    Columns(1).Insert
    End Sub
    Last edited by Aussiebear; 01-21-2023 at 03:23 AM. Reason: Adjusted code tags

  8. #8
    VBAX Regular
    Joined
    Apr 2013
    Posts
    14
    Location
    Thank you for all

  9. #9
    VBAX Newbie SendGroupSMS's Avatar
    Joined
    Jan 2023
    Location
    Delhi, India
    Posts
    1
    Location
    Is the VBA code provided in the solution worked for all the latest as well as old versions of MS Excel?

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,055
    Location
    Quote Originally Posted by SendGroupSMS View Post
    Is the VBA code provided in the solution worked for all the latest as well as old versions of MS Excel?
    Did you try it first?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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