wasy macro question

G

gls858

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
 
G

gls858

gls858 said:
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

That supposed to be easy macro question
 
B

Bob Phillips

The range is a single cell, but you use entirecolumn later.

I would just use

Columns(1).Autofit

or

Columns("A").Autofit

--
---
HTH

Bob


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

gls858

Bob said:
The range is a single cell, but you use entirecolumn later.

I would just use

Columns(1).Autofit

or

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
 
S

Sandy Mann

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

--
HTH

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

(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk
 
B

Bob Phillips

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.

--
---
HTH

Bob


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

gls858

Sandy said:
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

Thanks for the input Sandy.

gls858
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top