LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Query !!

Just finiding difficult in knowing what is below code is useful for it wld be great if some one explians with examples

Selection.CurrentRegion.Rows.Count - 1



Joe wrote:

I usually do something like thisLastRow = 0LastCol = 10For ColCount = 1 to 10
11-Nov-08

I usually do something like this

LastRow = 0
LastCol = 10
For ColCount = 1 to 10
LRow = cells(Rows.Count).End(xlup).Row
if LRow LastRow then
LastRow = LRow
end if
next i


"KenY" wrote:

Previous Posts In This Thread:

On Tuesday, November 11, 2008 7:35 AM
Ken wrote:

Error with Selection.CurrentRegion.Rows.Count?
Hi
I have previous experience of consolidating several worksheets into a single
worksheet and my method has worked well.
Typically, the method is:

'select a cell in the table, take a row count and copy it
Cells(5, 5).Select
Selection.CurrentRegion.Select
add_rows_cntr = Selection.CurrentRegion.Rows.Count
Selection.Copy

' paste the data values back into the consolidation
' check that there is space in the consolidation worksheet
If curr_rows_cntr + add_rows_cntr 65536 Then MsgBox "Spreadsheet
Overflow": GoTo abort_consolid_loop
Windows("CAT_Consolidation.xls").Activate
Sheets("All_CAT_Data").Activate
' select the first empty row in the consolidation worksheet and paste the
data
Cells(curr_rows_cntr + 1, 4).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

So far, so good. Except I now have a scenario where the row count of my
current region is returned=1, but the copied area is 31 rows long. When I
check things manually in the source worksheet, using the cntl* command to
identify the current region (having selected the same cell as in macro), the
full 31 row area is selected.

The cause of the difference seems to be where the blank cells lie within my
'CurrentRegion', but it bothers me that the Excel behaviour is not the same
for the statements
' add_rows_cntr = Selection.CurrentRegion.Rows.Count' and
' Selection.CurrentRegion.Select
Selection.Copy'

Has anyone come across this and found a solution?

Data area format that throws the problem (hope this shows up ok in the post):

Value1 <blank <blank <blank
<blank <blank <blank Head1
<blank Head2 Head3 Head4
head5 Head6 Head7 Head8
Value2 <blank Value3 Value4
Value5 Value6 Value7 <blank

If I make sure that the first column is continuous, when I select head5 as
my active cell for and ask for the CurrentRegion, I get the result I want.
As I said, I am more concerned that I have found an inconsistent behaviour
(Excel 2003) rather than wanting to know how I can fix my table.
--
KenY

On Tuesday, November 11, 2008 7:45 AM
Joe wrote:

I usually do something like thisLastRow = 0LastCol = 10For ColCount = 1 to 10
I usually do something like this

LastRow = 0
LastCol = 10
For ColCount = 1 to 10
LRow = cells(Rows.Count).End(xlup).Row
if LRow LastRow then
LastRow = LRow
end if
next i


"KenY" wrote:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Crypto Obfuscator for .NET - Product Review
http://www.eggheadcafe.com/tutorials...or-for-ne.aspx
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
extend selected CurrentRegion results in application or objectdefined error 1004 [email protected] Excel Programming 4 June 2nd 08 02:53 AM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Programming 0 May 3rd 08 01:03 AM
Selecting multiple rows within a CurrentRegion Brian J. Matuschak Excel Programming 1 May 18th 06 05:12 AM
Object Type of a selection... counting rows in a selection Acid-Sky[_2_] Excel Programming 3 August 23rd 05 09:53 AM
Count rows On error MsgBox Robert Christie[_3_] Excel Programming 4 February 24th 04 05:28 PM


All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"