Solved

Problem to the line

Posted on 2015-02-09
4
78 Views
Last Modified: 2015-02-09
Hi,
The original Excel file is version 2003, after I've re-saved it as Excel 2010 macro-enabled version, and then tried to run the macro, I get the attached problem, due to this line

        Range(objShtDst.Cells(intcurdstrow, 2), objShtDst.Cells(intcurdstrow, 6)).Select

Open in new window


why?
t968.png
0
Comment
Question by:HuaMinChen
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40597852
in a macro, you rarely need to actually "select" the range, but rather use the range object.
meaning that instead of doing:
range.Select
selection.dosomething

you do
range.dosomething
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40597862
Thanks. It has codes like

        Range(objShtDst.Cells(intcurdstrow, 2), objShtDst.Cells(intcurdstrow, 6)).Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
...

Open in new window


how to correct the problem to 1st line in above?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 40597885
this should not only work without the error, but will also run faster:
dim r as Range
set r =  Range(objShtDst.Cells(intcurdstrow, 2), objShtDst.Cells(intcurdstrow, 6))
        r.Borders(xlDiagonalDown).LineStyle = xlNone
        r.Borders(xlDiagonalUp).LineStyle = xlNone
        r.Borders(xlEdgeLeft).LineStyle = xlNone
        r.Borders(xlEdgeTop).LineStyle = xlNone

Open in new window

0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 100 total points
ID: 40597902
It's also better to qualify the Range call:

set r =  objShtDst.Range(objShtDst.Cells(intcurdstrow, 2), objShtDst.Cells(intcurdstrow, 6))

Open in new window

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

863 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

20 Experts available now in Live!

Get 1:1 Help Now