Ignoring Formulas When Searching For Next Empty Cell

ExcelAtEverything

Active Member
Joined
Jan 30, 2021
Messages
351
Office Version
  1. 2019
Platform
  1. Windows
Hello! The following was created to find the next empty cell within a range in column B, and then paste in info which was copied from O6:P6. The only problem is that it's not working correctly because I have cells in column B which contain formulas (fitted with an IFERROR prefix to keep some cells empty when there is no info to fill them). How can I edit this to ignore cells containing formulas in column B when looking for the next empty?

Sub AddExtraStoreToLocMasterList() '
' AddExtraStoreToLocMasterList Macro
' This macro copies O6:P6 to cipboard, then finds first blank cell in column B Loc Master List range, and the paste specials there.
'
Range("O6:P6").Select
Selection.Copy
Range("B4").Select
ActiveCell.End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("O6:P6").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("O6").Select
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi, you can check the next fill cells using if statement.

VBA Code:
totalRows = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To totalRows
    If ActiveSheet.Range("A" & i) <> "" Then
        totalRows = i
    End If
    
Next
 
Upvote 0
Can you explain to me what you mean, and how that applies? Sorry, I recorded that macro, and I'm still pretty new to VB. I can understand by looking thru it sometimes, but I'm not sure what I'm looking at in pretty much any part of your response. Lol
 
Upvote 0
try this which will check values and formula ;
VBA Code:
Sub AddExtraStoreToLocMasterList() 
inarr = Range("O6:P6")
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
bvalues = Range(Cells(1, 2), Cells(lastrow, 2))
Bformula = Range(Cells(1, 2), Cells(lastrow, 2)).Formula
 For i = 1 To lastrow
  If bvalues(i, 1) = "" And Bformula(i, 1) = "" Then
     Range(Cells(i, 15), Cells(i, 16)) = inarr
     Exit For
  End If
 Next i
 End Sub
 
Upvote 0
Hi,

Check below code. Made changes in existing code.

VBA Code:
Sub AddExtraStoreToLocMasterList() '
' AddExtraStoreToLocMasterList Macro
' This macro copies O6:P6 to cipboard, then finds first blank cell in column B Loc Master List range, and the paste specials there.
'
Range("O6:P6").Select
Selection.Copy

totalRows = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
For i = 4 To totalRows
    If ActiveSheet.Range("B" & i) <> "" Then
        totalRows = i
    End If
   
Next
Range("B" & totalRows + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("O6:P6").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("O6
 
Upvote 0
Saurabhj, looks like you only sent me part of the code. It looks cut off at the end.
 
Upvote 0
I just ran it again, but this time no error. It was 100% throwing an error yesterday. Not sure what's different now. That said, it still did not work. All it seems to do is place the contents above it in cells O1, P1. It doesn't place it into the range where I need it, and it doesn't then clear the cells after copy/pasting the info, and it doesn't then leave the curser back at O6.

1615087598059.png
 
Upvote 0
The problem might be because I started the search for a blank row from B1 not B4 so try this modification,. I have also put in the clear O6:P6 and selcting o6
VBA Code:
Sub AddExtraStoreToLocMasterList()
inarr = Range("O6:P6")
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
bvalues = Range(Cells(1, 2), Cells(lastrow, 2))
Bformula = Range(Cells(1, 2), Cells(lastrow, 2)).Formula
 For i = 4 To lastrow
  If bvalues(i, 1) = "" And Bformula(i, 1) = "" Then
     Range(Cells(i, 15), Cells(i, 16)) = inarr
     Exit For
  End If
 Next i
 Range("O6:P6") = ""
 Range("O6").Select
 End Sub
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

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