×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SelectionChange

SelectionChange

SelectionChange

(OP)
I've made the following to autofit the row of the cell I selected, but I want it to be the origin row height after another cell is selected.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Target.EntireRow.AutoFit
End Sub

RE: SelectionChange

Hi Robert:

Is Origin a fixed range, such as cell C3? ... if so then let us try ...

CODE

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Set Origin = Range("C3")
    Origin.EntireRow.AutoFit
End Sub

Yogi Anand, D.Eng, P.E.
Energy Efficient Building Network LLC
ANAND Enterprises LLC
http://www.energyefficientbuild.com

RE: SelectionChange

(OP)
Sorry, I did not describe it clearly.
Like this:
I select C3, the 3rd row becames autofit, I can read the whole data in this row.
And then, I select D4, then the 3rd row will be back to its origin height, like 12.75, and the 4th row becames autofit.....

RE: SelectionChange

You mean like:

CODE

Dim OldHt As Double
Dim NewHt As Double
Dim OldSel As Range


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If (Target.Row <> OldSel.Row) And (Target.Rows.Count = 1) Then
    
    If Not OldSel Is Nothing Then
        OldSel.RowHeight = OldHt
    End If

    Set OldSel = Target
    OldHt = Target.EntireRow.Height
    
    Target.EntireRow.AutoFit
    
End If
End Sub

RE: SelectionChange

(OP)
Thanks, handleman

As I run your codes, it says "Object variable or With block variable not set", it may points to OldSel.

I've tryed this kind of method before, set Oldsel as Target at end of program.

RE: SelectionChange

(OP)
I've got it solved:

Public ff, tt
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Rows(ff).RowHeight = tt
ff = Target.Row
tt = Target.RowHeight
    Target.EntireRow.AutoFit
End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources