Find first empty cell in row range-VBA

ljubo_gr

Active Member
Joined
Dec 6, 2014
Messages
251
Office Version
  1. 2013
Platform
  1. Windows
=Happy+New(Year(2017))

I have three sheets, they have columns A&B, ranges A2:A100, B2:B100. "A" range will always be shorter than B, if that means something. I need vba code to move my selector to First free cell in sheet1 "A"range, another code for "B"range, then another codes for Sheet2...Sheet3.
Thanks in advance kind people!
 
Last edited:
With a slight modification to SvenDiamonds code....might be quicker than a loop

Code:
Sub upArrow()
Dim foundBlank As Range
Set foundBlank = Range("A7:A77, G7:G77").Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub

How to and where to insert ThisWorkbook and Sheet1.Range...??
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Press ALT + F11
Dble click on ThisWorkbook
Paste into space on RH side where cursor is flashing

The code will work on any active worksheet
 
Upvote 0
No, i mean this workbook, i'll have several opened Excel files. And, i need it for sheet2 and sheet3.?
 
Upvote 0
No, i mean this workbook, i'll have several opened Excel files. And, i need it for sheet2 and sheet3.?
So the answer is: Michael M's code inside ThisWorkbook, upArrow is A7:A77range, downArrow code is G7:G77 range, insert arrow objects in Sheet1,2,3 and that's it?
 
Upvote 0
My code does the first empty cell in either range !!
If you want up / down separately use SvenDiamonds code with the ranges set

Code:
Sub upArrow()
Dim foundBlank As Range
Set foundBlank = Range("A7:A77").Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub

Sub DownArrow()
Dim foundBlank As Range
Set foundBlank = Range("G7:G77").Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub
 
Last edited:
Upvote 0
Yes, thanks very much. One final question, what if i have different ranges: Sheet1 A7:7 G7:7, Sheet2 A7:77 G7:77, Sheet3 A7:777...
Thanks in advance kind people!
 
Upvote 0
Assuming the ranges require the data to go to the last row/s in column A and G, try using

Code:
Sub upArrow()
Dim foundBlank As Range, lr as long
lr = cells(rows.count,"A").end(xlup).row
Set foundBlank = Range("A7:A" & lr).Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub

Sub DownArrow()
Dim foundBlank As Range, lr as long
lr = cells(rows.count,"G").end(xlup).row
Set foundBlank = Range("G7:G" & lr).Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub
 
Upvote 0
Yes, thanks very much. One final question, what if i have different ranges: Sheet1 A7:7 G7:7, Sheet2 A7:77 G7:77, Sheet3 A7:777...
Thanks in advance kind people!

No, i mean this workbook, i'll have several opened Excel files. And, i need it for sheet2 and sheet3.?

Any time you refer to a range it's going to be in this order:

Workbooks("yourBook").Worksheets("yourSheet").Range("yourRange")

If you just use Range() it's going to use the active sheet. If you use Worksheets().Range() it's going to assume the active workbook. If you want to specify which workbook or sheet you have to use those qualifiers. So to keep it in "ThisWorkbook" you can change it to:

Rich (BB code):
Sub upArrow()Dim foundBlank As Range
Set foundBlank = ThisWorkbook.Sheets("yourSheetName").Range("A7:A77").Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub


Sub DownArrow()
Dim foundBlank As Range
Set foundBlank = ThisWorkbook.Sheets("yourSheetName")Range("G7:G77").Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub
 
Upvote 0
Assuming the ranges require the data to go to the last row/s in column A and G, try using

Code:
Sub upArrow()
Dim foundBlank As Range, lr as long
lr = cells(rows.count,"A").end(xlup).row
Set foundBlank = Range("A7:A" & lr).Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub

Sub DownArrow()
Dim foundBlank As Range, lr as long
lr = cells(rows.count,"G").end(xlup).row
Set foundBlank = Range("G7:G" & lr).Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Sub

THANK YOU ALL! I'll stay with Michael M.
Is this(A7: ) range starts looking from A7 to down? Right?
 
Upvote 0
you could also use an Input to select which column

Code:
Sub upArrow()
Dim foundBlank As Range, lr As Long
ans = InputBox("Which Column Do you want to search, A or G ?")
Select Case ans
Case Is = "A"
lr = Cells(Rows.Count, "A").End(xlUp).Row
Set foundBlank = ThisWorkbook.ActiveSheet.Range("A7:A" & lr).Find(What:="", lookat:=xlWhole)
    foundBlank.Select
Case Is = "G"
lr = Cells(Rows.Count, "G").End(xlUp).Row
Set foundBlank = ThisWorkbook.ActiveSheet.Range("G7:G" & lr).Find(What:="", lookat:=xlWhole)
    foundBlank.Select
End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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