cod vba pentru latimea unei coloane la o anumita dimensiune in functie de o valoare din oricare celula din acea coloana

popa catalin

New Member
Joined
Aug 31, 2024
Messages
10
Office Version
  1. Prefer Not To Say
Platform
  1. Windows
Buna ziua
va rog sa ma ajutati cu urmatoarea problema:
sa dori un cod vba pentru dimensionarea coloanelor unui tabel la o anumia valoare in functie de o valoare care se regaseste in celulele unei coloane.

Mai exact: inr-un tabel daca de exemplu in oricare celula dintr-o coloana introduc cifra 8, acea coloana sa aiba column width=4, iar daca este alta valoare sa aiba column width =1.
si tot asa pentru oricare coloana din acel tabel.
mulumesc anticipat
 
Acum functioneaza exact cum ati spus dumneavoastra.
Eu as vrea daca pun orce valoare intr-o celula si daca pe coloana respectiva intalneste un 8 sa ramana latimea coloanei 5 ,iar daca pe coloana respectiva ne e nici un 8 atunci latimea coloanei sa fie 1.9
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Introduceți orice valoare sau text în zona D10:H50, acest cod va verifica dacă coloana care conține acea valoare sau text conține cifra 8; dacă da, atunci lățimea coloanei va fi setată la 5. Este corect așa?
PHP:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Or Intersect(Target, Range("D10:H50")) Is Nothing Then Exit Sub
With Target.EntireColumn
    If Application.Match(8, Intersect(Target.EntireColumn, Range("D10:H50")), 0) Then
        .ColumnWidth = 5
    Else
        .ColumnWidth = 1.9
    End If
End With
End Sub
 
Upvote 0

Attachments

  • WhatsApp Image 2024-09-03 at 07.01.33.jpeg
    WhatsApp Image 2024-09-03 at 07.01.33.jpeg
    224.7 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,224,043
Messages
6,176,047
Members
452,701
Latest member
rfhandel

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