Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2008

Tip: Looking for answers? Try searching our database.

wasy macro question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gls858 - 12 Mar 2008 23:51 GMT
I used the macro recorder to get the code to resize columns on a worksheet

Cells.Select
    Range("A1766").Activate
    Cells.EntireColumn.AutoFit

What I don't understand in the Range. It's seems to be referring to a
single cell. Could someone explain to a VBA newbie?

I'm importing a text file and I want to resize the columns after import.
I have the import working just need this one last thing.

The worksheet will always have the same number of columns but the number
of rows may vary will the above code still work?

gls858
gls858 - 12 Mar 2008 23:54 GMT
> I used the macro recorder to get the code to resize columns on a worksheet
>
[quoted text clipped - 12 lines]
>
> gls858

That supposed to be easy macro question
Bob Phillips - 13 Mar 2008 00:02 GMT
The range is a single cell, but you use entirecolumn later.

I would just use

Columns(1).Autofit

or

Columns("A").Autofit

Signature

---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

>I used the macro recorder to get the code to resize columns on a worksheet
>
[quoted text clipped - 12 lines]
>
> gls858
gls858 - 13 Mar 2008 00:10 GMT
> The range is a single cell, but you use entirecolumn later.
>
[quoted text clipped - 5 lines]
>
> Columns("A").Autofit

Thanks Bob. I just posted what the recorder recorded. I'm a newbie when
it comes to VBA. I'll give your suggestion a try.

gls858
Bob Phillips - 13 Mar 2008 09:23 GMT
That is the problem with the MR, it records every step. So you select a
cell, then you autofit the column, two steps, so that is what the MR
records. A bit of a pain, but understandable.

Signature

---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

>> The range is a single cell, but you use entirecolumn later.
>>
[quoted text clipped - 10 lines]
>
> gls858
Sandy Mann - 13 Mar 2008 00:14 GMT
This is what I get in XL97 when I use the Macro Recorder:

Cells.Select
   Selection.Columns.AutoFit

You can of course take out the two Selects and just have:

Cells.Columns.AutoFit

Signature

HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings

sandymann2@mailinator.com
Replace @mailinator.com with @tiscali.co.uk

>I used the macro recorder to get the code to resize columns on a worksheet
>
[quoted text clipped - 12 lines]
>
> gls858
gls858 - 13 Mar 2008 19:19 GMT
> This is what I get in XL97 when I use the Macro Recorder:
>
[quoted text clipped - 4 lines]
>
> Cells.Columns.AutoFit

Thanks for the input Sandy.

gls858
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.