2 VBA Issues w/column size and return to A1

jae113

Board Regular
Joined
Jun 17, 2008
Messages
227
Hi All,

I'm pretty new at VBA, I've been using Macro Recorder in 2010 and working from there, so I apologize if any of this is a silly question.

Without having to re-record entire process, is there a way to write in an absolute return to A1 from any where in the workbook? I used releative references and a few little macros (that I would like to combine eventually) but I didn't record the return to A1. I tried Range("A1") .Select but got a syntac error

I have a two part issue with the column size and width. When the data comes in from Access, some is wrapped and the columnn width is wacky. I would like to make all the columns "fit to size" and manually to fix the wrap issue, is I select the entire worksheet and then wrap and unwrap it. Here is the code I used, but it doesn't seem to do anything:

Sub Wrap_Unwrap_Text()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
'' Wrap_Unwrap_Text Macro<o:p></o:p>
''<o:p></o:p>
ActiveCell.Cells.Select<o:p></o:p>
With Selection<o:p></o:p>
.VerticalAlignment = xlBottom<o:p></o:p>
.WrapText = True<o:p></o:p>
.Orientation = 0<o:p></o:p>
.AddIndent = False<o:p></o:p>
.IndentLevel = 0<o:p></o:p>
.ShrinkToFit = False<o:p></o:p>
.ReadingOrder = xlContext<o:p></o:p>
.MergeCells = False<o:p></o:p>
End With<o:p></o:p>
With Selection<o:p></o:p>
.VerticalAlignment = xlBottom<o:p></o:p>
.WrapText = False<o:p></o:p>
.Orientation = 0<o:p></o:p>
.AddIndent = False<o:p></o:p>
.IndentLevel = 0<o:p></o:p>
.ShrinkToFit = False<o:p></o:p>
.ReadingOrder = xlContext<o:p></o:p>
.MergeCells = False<o:p></o:p>
End With<o:p></o:p>
End Sub<o:p></o:p>


Any and all help very much appreciated! Thanks!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You don't need to select cells to perform actions on them, which means you don't need to return to A1. Something like this...

Code:
Sub Wrap_Unwrap_Text()
With Cells
    .WrapText = True
    .WrapText = False
    .EntireColumn.AutoFit
End With
End Sub

If you want to ensure A1 is selected after the code has run, your original line of Range("A1").Select should have worked.
 
Upvote 0
Thanks for getting back to me! The wrap and unwrap works great now. I'm having a lot of odd problems with the macro that I think are related to relative references, but I'm working on it.

For instance, I finally got almost all of my custom footer to work, with the exception that I can't seem to keep &n[] to stay on. It gives me the &p[], but always drops the total pages.


Thanks again :)
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,896
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top