vietkid221992
Thành viên chính thức
- Tham gia
- 26/8/22
- Bài viết
- 63
- Được thích
- 30
Sub SelectColunms()
Dim Rws As Long, Col As Integer, J As Long
Dim Rng As Range
Rws = Sheets("GPE").UsedRange.Rows.Count
If Rws > 1 Then
Col = MsgBox("Hay Chi Sô Chon Côt Bát Dâu:")
Set Rng = Cells(1, Col).Resize(Rws)
For J = 2+Col To 200 Step 2
Set Rng = Union(Rng, Cells(1, J).Resize(Rws))
Next J
End If
Rng.Select: MsgBox Rng.Cells.Count
End Sub
Option Explicit
Sub SelectEvenColumn()
Dim i&, rng As Range, u As Range
Set rng = Range("D1:GU1") ' dong dau tien cua vung muon chon
For i = 1 To rng.Columns.Count
If i Mod 2 = 0 Then ' = 0=>chan, =1 => le
If u Is Nothing Then
Set u = rng.Range(Cells(1, i), Cells(200, i)) ' 200 = dong cuoi
Else
Set u = Union(u, rng.Range(Cells(1, i), Cells(200, i)))
End If
End If
Next
u.Select
End Sub
em cảm ơn ạVí dụ, mong bạn có thể tham khảo tí chút nào đó & vui nha:
PHP:Sub SelectColunms() Dim Rws As Long, Col As Integer, J As Long Dim Rng As Range Rws = Sheets("GPE").UsedRange.Rows.Count If Rws > 1 Then Col = MsgBox("Hay Chi Sô Chon Côt Bát Dâu:") Set Rng = Cells(1, Col).Resize(Rws) For J = 2+Col To 200 Step 2 Set Rng = Union(Rng, Cells(1, J).Resize(Rws)) Next J End If Rng.Select: MsgBox Rng.Cells.Count End Sub