Solved

VBA RowTo .... stop it from going to end

Posted on 2013-12-09
3
191 Views
Last Modified: 2013-12-11
I have the folowing code that will copy data from one sheet to another but when there is no data to copy it falls over and tell me Excel can not continue with available resources

WS.Range(RowFM & ":" & RowTO).EntireRow.Copy WSCopy.Cells(MaxRowCopy, "A")

When I hover over RowTo it tells me it returns 1048576

How do I stop it from falling over and trying to go to 1048576

Thanks
0
Comment
Question by:Jagwarman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39705874
Hi

How is RowTO defined ?

If RowTO = 1048576 Then
    MsgBox "No Data"
Else
    WS.Range(RowFM & ":" & RowTO).EntireRow.Copy WSCopy.Cells(MaxRowCopy, "A")
End If

Open in new window

Regards
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39705877
How do you calculate RowTo?
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39707821
Typically, people encounter this problem by using SomeCell.End(xlDown) if there are no data below SomeCell. In such a case, xlDown doesn't stop until the bottom row in the worksheet (1048576). As an alternative, consider either looking up from the bottom or testing whether the next cell contains data. Both options are shown in the snippet below. As written, they assume you are looking in column A, and have already established a value for the Long variable RowFM.
RowTO = Cells(Rows.Count, "A").End(xlUp).Row

RowTO = RowFM
If Not IsEmpty(Cells(RowFM + 1, "A")) Then RowTO = Cells(RowFM, "A").End(xlDown).Row

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

631 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