+ Reply to Thread
Results 1 to 14 of 14

Put "');" above each empty cell in selection

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-12-2007
    Location
    Germany
    MS-Off Ver
    2007
    Posts
    472

    Put "');" above each empty cell in selection

    Hello every one,

    i need a code which looks for empty cells in the selection and puts "');" in the cell above it. If the cells above the empty one already have content that should be deleted and "');" should be pasted there instead. I need to put this symbol combination above all empty cells in my selection.

    Thank you for your help in advance.
    Last edited by wali; 01-18-2010 at 03:40 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Put "');" above each empty cell in selection

    Hi wali
    Option Explicit
    Public Sub DoItptest()
    Dim rngData As Range, rng As Range
    With ActiveSheet
        Set rngData = Selection
        For Each rng In rngData
       If Not IsEmpty(rng) Then rng.Offset(-1, 0) = "');"
         Next
    End With
     Set rngData = Nothing
    End Sub
    after 270 posts you should attach your efforts instead of I need
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Contributor
    Join Date
    11-12-2007
    Location
    Germany
    MS-Off Ver
    2007
    Posts
    472

    Re: Put "');" above each empty cell in selection

    Hi Pike,

    I try to understand each time the code to of solutios so that i can try on my own next time. But as having Dyscalculia i cant. I hope that it will come and its my wish that some time i can give back this forum what i was given.

    Thank you very much for your help.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Put "');" above each empty cell in selection

    Without a loop, this might do it for you:

    Sub AddText()
    
         Selection.SpecialCells(xlCellTypeBlanks).Offset(-1, 0) = "');"
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Contributor
    Join Date
    11-12-2007
    Location
    Germany
    MS-Off Ver
    2007
    Posts
    472

    Re: Put "');" above each empty cell in selection

    Hi JBeaucaire,

    thank you very much for your help.

  6. #6
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Put "');" above each empty cell in selection

    Seens I late, but in any case i'm posting code

    Sub Test2()
    Dim lCell As String, rCell As Range
    
        For Each rCell In Selection
            If rCell = vbNullString Then
                If rCell.Row = 1 Then GoTo oops
                    With rCell
                        Cells(.Row - 1, .Column).FormulaR1C1 = ")"
                    End With
    oops:       End If
        Next rCell
    End Sub
    Last edited by contaminated; 01-18-2010 at 03:37 AM.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  7. #7
    Forum Contributor
    Join Date
    11-12-2007
    Location
    Germany
    MS-Off Ver
    2007
    Posts
    472

    Re: Put "');" above each empty cell in selection

    Dear Pike,

    Sorry i was too quick with marking it solved. Your code replaces all cells with "');". But only those which are above empty one should get "');" as their content. I am sending an example file in which the cells A19, A29 and A48 should get the content "');".
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    11-12-2007
    Location
    Germany
    MS-Off Ver
    2007
    Posts
    472

    Re: Put "');" above each empty cell in selection

    Dear contaminated,
    thank you very much. Your code worked for me when i changed the column names from A to the one i need to make changes in. Thank you very much.

  9. #9
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Put "');" above each empty cell in selection

    Really?!. I really didn't expected

    If so. please mark thread as solved and add reputation pls....

    EDIT
    Already marked as solved

  10. #10
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Put "');" above each empty cell in selection

    strange... going back to nuts and bolts try..
    With ActiveSheet
        Set rngData = Selection
       For Each rng In rngData
       If rng = "" Then
       rng.Offset(-1, 0).Value = "');"
        rng.Value = ""
        End If
        Next rng
    End With

  11. #11
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Put "');" above each empty cell in selection

    Hey contaminated
    never ever to late. its allways go to see other options and every ones efforts
    how else do we learn
    hi wali
    Ive tested this one

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Put "');" above each empty cell in selection

    I still think my loopless code does what you want. If you want the macro to figure out what to highlight on its own, then maybe:

    Sub AddText()
    Dim LR as Long:    LR = Range("D" & Rows.Count).End(xlUp).Row
    
    Range("D2:D" & LR).SpecialCells(xlCellTypeBlanks).Offset(-1, 0) = "');"
    
    End Sub

  13. #13
    Forum Contributor
    Join Date
    11-12-2007
    Location
    Germany
    MS-Off Ver
    2007
    Posts
    472

    Re: Put "');" above each empty cell in selection

    Hi you all three,
    now i have three working solutions. Thank you very very much.

  14. #14
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Put "');" above each empty cell in selection

    three times as happy

+ 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