Solved

Check for null

Posted on 2013-06-05
2
234 Views
Last Modified: 2013-06-09
I need to skip this step if A2 of the Manual Sheet is null.  Is there a way to do that?

Dim lastCol As Long, lastRow As Long

   
    With Sheets("Manual")
        'lastCol = .Cells(2, .Columns.Count).End(xlToLeft).column
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        .Range("A2", .Cells(lastRow, 1)).Copy
        '.Range("A2", .Cells(Rows.Count, "A")).Copy
       .Range("A2:A300").Copy
    End With

   
    With Sheets("Cus_tmp")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        If lastRow = 1 And .Cells(1) = "" Then lastRow = 0
        .Cells(lastRow + 1, "A").PasteSpecial Paste:=xlPasteValues, _
            Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
0
Comment
Question by:leezac
2 Comments
 
LVL 13

Assisted Solution

by:Shanan212
Shanan212 earned 150 total points
ID: 39222907
if sheets("Manual").range("A2").value <> vbnullstring then

end if

Open in new window

   
Use above: It checks to see if A2 is not equal to null. You can put your code inside the if-statement so that it will only run if A2 is not equal to null.
0
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 350 total points
ID: 39222920
Hi,

Depending on whether you mean 'Null' or 'Empty'...

If Not(IsEmpty(Worksheets("Manual").Range("A2"))) Then
   With Sheets("Manual")
        'lastCol = .Cells(2, .Columns.Count).End(xlToLeft).column
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        .Range("A2", .Cells(lastRow, 1)).Copy
        '.Range("A2", .Cells(Rows.Count, "A")).Copy
       .Range("A2:A300").Copy
    End With

   
    With Sheets("Cus_tmp")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        If lastRow = 1 And .Cells(1) = "" Then lastRow = 0
        .Cells(lastRow + 1, "A").PasteSpecial Paste:=xlPasteValues, _
            Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With 
End If

Open in new window


OR

If Not(IsNull(Worksheets("Manual").Range("A2"))) Then
...
End If

Open in new window



PS. Note I used the Worksheets() collection, not Sheets() like you did.

BFN,

fp.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now