• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Particular Range is Empty or not check

Abhijeet

Active Member
Hi

I want to identify particular range row wise if any value then copy that row not entire row but range of that row want to copy and paste in sheet4 please tell me how to do this

Range is N2:T100

This code is checking whole Row i want to check in particular range
Code:
Sub T1()
Dim row As Range
Dim sheet As Worksheet
Set sheet = ActiveSheet

For i = 1 To sheet.UsedRange.Rows.Count

    Set row = sheet.Rows(i)
    If WorksheetFunction.CountA(row) = 0 Then
        MsgBox "row " & i & " is empty"
    End If

Next i
End Sub
 
Hi !

Dim {Range variable} As Range
For Each {Range variable} In {Source Range}.Rows
If Application.CountA({Range variable}) Then {Range variable}.Copy {Destination}
…​
 
Hi
I tried but not work this please tell me
Code:
Sub T1()
Dim row As Range
Dim sheet As Worksheet
Set sheet = ActiveSheet

For Each row In Range("A1:D5").Rows

    Set row = sheet.Rows(i)
    If Application.CountA(row) Then row.Copy
        MsgBox "row " & i & " is empty"
    End If

Next i
End Sub
 
Why are you setting row = sheet.Rows(i)?

With Marc's code, you are not even using i...

Remove that line.
 
What do you mean your are not doing this?
Code:
Sub T1()
Dim row As Range
Dim sheet As Worksheet
Set sheet = ActiveSheet

For Each row In sheet.Range("A1:D5").Rows
    Set row = sheet.Rows(i) 'This line needs to be removed
    If Application.CountA(row) Then 
        row.Copy 'You need to set paste destination here
    Else 'You need else or you are showing message when condition is met
        MsgBox "row " & i & " is empty" 
    End If
Next i 'This should not be i but row since you are looping each row
End Sub
 
Sub T1()
Dim row As Range
Dim sheet As Worksheet
Set sheet = ActiveSheet


For Each row In Range("A1:D5").Rows

Set row = sheet.Rows(i)
If Application.CountA(row) Then row.Copy {Destination}
MsgBox "row " & i & " is empty"
End If

Next i
End Sub
 
What do you mean your are not doing this?
Code:
Sub T1()
Dim row As Range
Dim sheet As Worksheet
Set sheet = ActiveSheet

For Each row In sheet.Range("A1:D5").Rows
    Set row = sheet.Rows(i) 'This line needs to be removed
    If Application.CountA(row) Then
        row.Copy 'You need to set paste destination here
    Else 'You need else or you are showing message when condition is met
        MsgBox "row " & i & " is empty"
    End If
Next i 'This should not be i but row since you are looping each row
End Sub

Great piece of code.
 
Hi

Please tell me when this macro run that time if any value find in this then apart from this range tow different column value want to paste please tell me
Code:
If Application.CountA(row) Then row.Copy
 
Back
Top