VBA to Search Column for Blanks then Copy/Paste Based on the Blank Cell Location

clerario

New Member
Joined
Aug 24, 2011
Messages
3
I am attempting to search through a dynamic column which may have x number of blank cells and y number of cells with dates. I want to search the column for the first blank cell, then copy the cell immediately above it and paste it on a new sheet, I also want to copy the cell immediately below the blank cell and paste that on a different column in that new sheet. I want to repeat this so that I have a column of all cells above the blank cells from the original sheet in the new sheet and a separate column for all cells below in the new sheet.

this is my code which does not work fully, and also takes and copy's a different cell in the last column, which I need to do as well.

"Dim lRealLastRow As Long
Dim lRealLastColumn As Long
Dim i As Integer
Dim intRowCount As Integer

intRowCount = Sheets("Damages").Range("P1")

For i = 1 To intRowCount

Range("A1").Select
On Error Resume Next
lRealLastRow = Cells.Find("*", Range("A1"), xlFormulas, , xlByRows, xlPrevious).Row
lRealLastColumn = Cells.Find("*", Range("A1"), xlFormulas, , xlByColumns, xlPrevious).Column
Cells(lRealLastRow, lRealLastColumn).Select
Selection.copy
Sheets("Temp Data").Select
Sheets("Temp Data").Range("D1").Select
Range(D1).Select
Range("D1").End(xlDown).Select

If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.Select
End If


Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Review").Select
ActiveCell.Offset(1, -4).Select

Next i
End Sub"
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Let's simplify.

1) in the active sheet, examine all the cells in one column (column D?) looking for blanks

2) For each blank found, put the cell above into a new sheet (Sheet "Report" ?) in column A and the cell below next to it in column B.

3) Repeat for all blank cells in the specified column


Please correct the sheet names and column references, I'm sure we can get something simple for you.
 
Upvote 0
Yes, I want to search for a blank in the ActiveSheet ("Review" in my case) column A and then

For each blank found, put the cell above into a new sheet (Sheet "Temp Data" ) in column A and the cell below next to it in column B.

and yes Repeat for all blank cells in the specified column
 
Upvote 0
Give this a whirl, this assumes these cells are truly blank, not just blank in appearance:
Code:
Option Explicit

Sub BlankReview()
Dim blankRNG As Range, blank As Range, NR As Long

On Error Resume Next
Set blankRNG = ActiveSheet.Range("A:A").SpecialCells(xlBlanks)

    If Not blankRNG Is Nothing Then
        With Sheets("Temp Data")
            NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
        
            For Each blank In blankRNG
                .Range("A" & NR).Value = blank.Offset(-1).Value
                .Range("B" & NR).Value = blank.Offset(1).Value
                NR = NR + 1
            Next blank
        End With
    Else
        MsgBox "No blank cells found in column A"
    End If
End Sub
 
Upvote 0
Thank You Sir! After some tweaking it works just like I want it to, I had to clear the columns in "Temp Data" before the macro is run each time and added:
Range("F" & NR).Value = blank.Offset(-1, 4).Value

because I needed one more cell on "Review" transferred to "Temp Data"
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top