VBA IsEmpty Function not working properly

cg1576

New Member
Joined
Nov 24, 2017
Messages
6
Hi,
I have a database of our clients, and the columns are arranged in the following way
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[/TR]
[TR]
[TD]ID[/TD]
[TD]NAME[/TD]
[TD]PHONE[/TD]
[TD]ADDRESS[/TD]
[TD]CITY[/TD]
[TD]STATE[/TD]
[TD]ZIP[/TD]
[TD]WEBSITE[/TD]
[TD]E-MAIL/CONTACT FORMS[/TD]
[TD]INDUSTRY[/TD]
[TD]STATUS[/TD]
[/TR]
</tbody>[/TABLE]



I have the following macro, which works great. It basically loops through the database and pulls up the Name (B) and e-mail/contact form (I) of those that meet the two criteria (which are *http* in I and "Sent" in K).

Code:
Dim LastRow As Long
   Dim i As Long, j As Long


   'Find the last used row in a Column: column A in this example
   With Worksheets("Tracker")
      LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
   End With


   MsgBox (LastRow)
   'first row number where you need to paste values in Sheet1'
   With Worksheets("Contact Form To Send")
      j = .Cells(.Rows.Count, "A").End(xlUp).Row
   End With


   For i = 2 To LastRow
       With Worksheets("Tracker")
           If InStr(.Cells(i, 9).Value, "http") And .Cells(i, 11).Value = "Sent" Then
               .Cells(i, 2).Copy Destination:=Worksheets("Contact Form To Send").Range("A" & j)
               .Cells(i, 9).Copy Destination:=Worksheets("Contact Form To Send").Range("B" & j)
               j = j + 1
           End If
       End With
   Next i

Now I have four different status options and some of them do not have a status (empty cell in K). I want to pull up those that do not have a status, but the IsEmpty function doesn't seem to work, it just pulls ALL the rows that meet the first criteria, regardless of the K column.

Code:
Dim LastRow As Long
   Dim i As Long, j As Long


   'Find the last used row in a Column: column A in this example
   With Worksheets("Tracker")
      LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
   End With


   MsgBox (LastRow)
   'first row number where you need to paste values in Sheet1'
   With Worksheets("Contact Form To Send")
      j = .Cells(.Rows.Count, "A").End(xlUp).Row
   End With


   For i = 2 To LastRow
       With Worksheets("Tracker")
           If InStr(.Cells(i, 9).Value, "http") And IsEmpty(Cells(i, 11)) Then
               .Cells(i, 2).Copy Destination:=Worksheets("Contact Form To Send").Range("A" & j)
               .Cells(i, 9).Copy Destination:=Worksheets("Contact Form To Send").Range("B" & j)
               j = j + 1
           End If
       End With
   Next i

I am new to VBA, I have tried different iterations based on different things I saw online such as: IsEmpty(Range("K" & i).Value) and even IsEmpty(Cells(i, 11)) = True. I don't get any errors, the macro runs its course, it just doesn't seem to take the IsEmpty function into consideration.


Any help would be very appreciated.

CG
 
Last edited by a moderator:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You've forgotten the . before Cells
Code:
IsEmpty(.Cells(i, 11))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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