Using Code to Adjust Specific Column Width

  • Thread starter Thread starter Nigel Bennett
  • Start date Start date
N

Nigel Bennett

I have a spreadsheet that retrieves data after it has
retreived the data I want to use code to look in row 5 and
go thru each cell up to the last colum, if there is
nothing in the cell I want it to resize it to a smaller
size,

is there anyway of doing this

Thanks
 
If Application.COUNTA(Range("C:C") = 0 Then
Range("C:C").ColumnWidth = 5
End If
 
No the code didn't work I had the following entered

If application.CountA(range("A5,CG5")) = 0 Then
range("A5,CG5").ColumnWidth = 5
End If

any help
 
How about the following:


Dim Rng As Range
Dim oCell As Range
Dim LastCol As Range

Set LastCol = Cells(5, Columns.Count).End(xlToLeft)
Set Rng = Range(Cells(5, 1), LastCol)

For each oCell in Rng
If oCell="" then oCell.ColumnWidth=5
Next oCell
 

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

Back
Top