简体   繁体   中英

Excel VBA check 3 cells in row range include a string

I have a Range("S4:U72") and I need to make sure that there is only text in either column. Therefore it must not have text in 2 or more columns on the same row.

I know I can use "For each cell in Selection" and I know I can use WorksheetFunction.CountA("S4:U4") > 2

I just don't know how to put the 2 together so that it applies the formula to each row in the table.

Example在此处输入图片说明

I finally worked it out:

Dim rng As Range, row As Range, cell As Range

Set rng = Range("S4:U72")

For Each row In rng.Rows
  For Each cell In row.Cells
    If WorksheetFunction.CountA(Range(row.Cells.Address(0, 0))) > 1 Then
        MsgBox "You can only assign one value to a row"
    End If
  Next cell
Next row

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM