Checking if a worksheet is empty otherwise should go to the final row of the data

Ricardo Caicedo

New Member
Joined
Aug 21, 2014
Messages
43
Hello Again Gurus</SPAN>

I am trying to copy and paste information from several worksheets to a main sheet named ‘Burn Reports”, but I need to check if a worksheet has a row already copied (so that means that a second filed needs to be appended).</SPAN>

I use the next code in RED</SPAN> but</SPAN> for some reason is not working anymore; the value for the range named as “rRNG” is 1(one) even though there is nothing in the file, so it shoul be zero.The variable eEmptyS does not get true...</SPAN>

While Len(fName) > 0</SPAN>
Set wbkOld = Workbooks.Open(fName)</SPAN>
'Sheets(1).Activate</SPAN>
wbkOld.Sheets(1).Cells.Find(What:="Rate", After:=ActiveCell, LookIn:=xlValues, LookAt:= _</SPAN>
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _</SPAN>
False, SearchFormat:=False).Activate</SPAN>
wbkOld.Sheets(1).Cells.FindNext(After:=ActiveCell).Activate</SPAN>
wbkOld.Sheets(1).Cells.FindNext(After:=ActiveCell).Activate</SPAN>
ActiveCell.Offset(2, 0).Range("A1").Select</SPAN>
Range(Selection, Selection.End(xlToRight)).Select</SPAN>
Range(Selection, Selection.End(xlDown)).Select</SPAN>
Selection.Copy</SPAN>
wbkNew.Worksheets("Burn Reports").Activate 'assumes data starts in A1</SPAN></SPAN>
Set rRNG = wbkNew.Worksheets("Burn Reports").Cells(1, 1).CurrentRegion
</SPAN></SPAN>
If rRNG.Cells.Count = 0 Then 'no data in master sheet
</SPAN></SPAN>
eEmptyS = True
</SPAN></SPAN>
Else: eEmptyS = False
</SPAN></SPAN>
End If
</SPAN></SPAN>
If eEmptyS Then</SPAN>
ActiveSheet.Paste</SPAN>
Else:</SPAN>
Range("A1").Select</SPAN>
Selection.End(xlDown).Select</SPAN>
ActiveCell.Offset(2, 0).Range("A1").Select</SPAN>
ActiveSheet.Paste</SPAN>
End If</SPAN>
fName = Dir</SPAN>
wbkOld.Close False</SPAN>

Loop</SPAN>


Any Suggestions please</SPAN>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If a worksheet is empty then by your code rRNG is cell A1. So, the count of cells in rRNG is 1.

Maybe try:
If Application.Counta(rRNG) = 0 Then '<--- rRNG is empty
 
Upvote 0

Forum statistics

Threads
1,226,223
Messages
6,189,710
Members
453,566
Latest member
ariestattle

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