Results 1 to 3 of 3

Find 1st Empty Cell in Column D Only If Column B On same Row as Empty Cell, is Not Empty

Threaded View

Zedcars Find 1st Empty Cell in Column... 01-05-2022, 06:46 PM
jindon Re: Find 1st Empty Cell in... 01-05-2022, 09:18 PM
Zedcars Re: Find 1st Empty Cell in... 01-06-2022, 05:46 PM
  1. #1
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    Find 1st Empty Cell in Column D Only If Column B On same Row as Empty Cell, is Not Empty

    Hello,

    I've been struggling with this problem for a few days now.

    I have 2 Workbooks (WB1 and WB2). WB2 contains links copied from the same cells in WB1.

    I need to write some code that finds the first empty cell in column D AND the cell in same row in column B has data (all cells have links). If the cell in the same row (as the empty D cell) in B is also empty, then the search should resume in the next sheet, and so on until a cell matching the conditions is met and the cell is copied.

    The following code seems to work perfectly in WB1 which has no link cells. But as soon as it is tried in WB2 (with the link cells) it fails because the IsEmpty function sees the link address as data. I'm guessing I would need to use Find("", LookIn:=xlValues) so it is only searching the values of the link cells, rather than the link address itself.

    Option Explicit
    
    Sub Find_Next_Empty_In_Links1()
    '
    ' Find_Next_Empty_In_Links Macro
    '
    
    '
    Dim Rng1 As String
    Dim i As Long
    Dim shtCount As Long
    
    shtCount = Sheets.Count
    
    For i = 1 To shtCount
    
                If IsEmpty(Sheets(i).Range("D:D").Find("", LookIn:=xlValues).Offset(0, -2).Value) = False Then
                    Sheets(i).Activate
                    Sheets(i).Range("D:D").Find("", LookIn:=xlValues).Offset(0, -2).Copy
                    Exit For
                End If
    
    Next i
    End Sub
    The next code only works in WB2 sheet 2 or 3 where there are still, for example, an empty cell in D5 with B5 containing data. If it is used on WB2 sheet 1 then I get the Run-time error '91': Object variable or with block variable not set.

    
    Sub Find_Next_Empty_In_Links2()
    '
    ' Find_Next_Empty_In_Links Macro
    '
     
    '
     
    Dim Rng1 As String
    
    Rng1 = Range("B:B").Find("", LookIn:=xlValues).Offset(-1, 0).Address
    Range("D2:" & Rng1).Find("", LookIn:=xlValues).Offset(0, -2).Select
    End Sub
    I understand the error is because, if it cannot find an empty cell in column D which also has data in the same row column B, then I need to tell it to search the next sheet and so on until a cell matching those conditions is found. Exactly how to do this though is where I'm falling down.

    Any help you can give me would be amazing as I'm going bald fast trying to figure this out!
    Attached Files Attached Files
    Last edited by Zedcars; 01-05-2022 at 06:54 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Move last cell in column to the next right empty cell if row in sheet is empty
    By Daijhan97 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2019, 07:05 AM
  2. [SOLVED] Using macro to find first empty cell in column. If range is empty returns error.
    By A440 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-23-2019, 11:03 AM
  3. [SOLVED] vba code to find and paste data to next empty cell, not last empty cell
    By hkbhansali in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2018, 10:48 AM
  4. [SOLVED] Paste formula to the last empty cell based on a non-empty cell on another column
    By bhenlee in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-02-2015, 04:07 PM
  5. Excel VBA evaluate if Cell in column D is empty and Cell in column A is not empty
    By Jovillanueva in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-02-2014, 08:09 PM
  6. Replies: 5
    Last Post: 05-13-2014, 10:19 AM
  7. Need to find empty filled cells in a column and copy to the empty cell below
    By Grahamfeeley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-30-2014, 10:09 AM

Tags for this Thread

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