LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Formatting and sorting cells with VBA

I need to apply date formatting to column A and then sort the entire
worksheet by column A ascending. I don't know how many rows/columns there
will be, but row 1 is always the header row.

I calculate the last row and column like this:

lc = .Range("A1").SpecialCells(xlCellTypeLastCell).Colu mn
lr = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
(no problem using SpecialCells here)

I've tried the following VBA code, but no luck:

With xlapp.Workbooks(strXlsFile).Worksheets(sn(i))
.Range("A2:A" & lr).NumberFormat = "mm/dd/yyyy hh:mm;@"
End with

With xlapp.Workbooks(strXlsFile).Worksheets(sn(i))
.Range(.Cells(2, 1), .Cells(lr, lc)).NumberFormat = "mm/dd/yyyy hh:mm;@"
End with

Why is this not working? The macro recorder returns this:

Range("A2:A106").Select
Selection.NumberFormat = "mm/dd/yyyy hh:mm;@"

Do I need to select the range in VBA??

Thanks in advance.


 
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
Sorting Cells with Conditional Formatting Edie Excel Discussion (Misc queries) 2 June 3rd 08 02:21 AM
Date Formatting & Sorting Irfan Khan[_2_] Excel Discussion (Misc queries) 2 April 4th 08 06:00 PM
Sorting with Formatting Patricia Excel Discussion (Misc queries) 4 December 8th 07 12:59 AM
Formatting Date for Sorting KP Excel Discussion (Misc queries) 2 September 18th 06 05:10 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


All times are GMT +1. The time now is 01:34 AM.

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

About Us

"It's about Microsoft Excel"