Finding range of first empty cell in column and set as variable's range...

MistakesWereMade

Board Regular
Joined
May 22, 2019
Messages
103
I've listed my code below. I want to be able to set the first empty cell's range in a column equal to the range of variable "PasteCell". However, with my code, I get the error "Method 'Range' of object '_Global' failed when trying to msgbox the row location of PasteCell.

Any ideas?

Code:
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
Dim PasteCell As Variant


With Sheets("Inventory")


sourceCol = 7   'column F has a value of 6
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row


    'for every row, find the first blank cell and select it
    For currentRow = 3 To rowCount
        currentRowValue = Cells(currentRow, sourceCol).Value
        If IsEmpty(currentRowValue) Or currentRowValue = "" Then
            PasteCell = Sheets("Inventory").Range(currentRow & sourceCol)
        End If
    Next


MsgBox (Range(PasteCell).Row)


End With
 
Well, I tried those suggestions, but I just couldn't get it. Finally it took the below code for me to get the desired effect. currentRow was giving me the right row of the first blank cell and I knew what column the blank should be in, so I just did PasteCell = "G" and currentRow and was then able to save the blank cell as PasteCell.

Thanks for helping guys!!!

Code:
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
Dim PasteCell As Variant


With Sheets("Inventory")


sourceCol = 7
rowCount = .Cells(Rows.Count, sourceCol).End(xlUp).Row


    'for every row, find the first blank cell and select it
    For currentRow = 3 To rowCount
        currentRowValue = .Cells(currentRow, sourceCol).Value
        If IsEmpty(currentRowValue) Or currentRowValue = "" Then
            Set PasteCell = .Cells(currentRow, sourceCol)
        End If
    Next


PasteCell = "G" & currentRow
Sheets("Inventory").Range(PasteCell) = Sheets("Inventory").Range(a).Value
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Glad you got it working & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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