[英]How do I write a loop in VBA that will delete a row if a cell in a range and the cell next to it both equal a constant?
[英]How do I loop across both rows and columns of a range in VBA?
我正在嘗試僅使用單元格值創建甘特圖類型顯示。 由於格式,公式無法正常工作,因此我需要運行VBA。
我想遍歷單個命名范圍的列和行。 但是,我認為VBA格式不正確,因為這樣會出現錯誤“ 438:對象不支持此屬性或方法”
Dim d As Integer
Dim e As Integer
For d = 1 To **Range("PRcal").Cols.Count**
For e = 1 To **Range("PRcal").Rows.Count**
If [Range("PRcal").Cells.(e, d).Value = Range("PRcal").Cells(1, d).Value] Then
Cells(e, d).Value = Cells(e, 1)
End If
Next e
Next d
有什么建議么? 謝謝!
Cols
屬性-它們具有Columns
屬性 if
在Cells.(e,d)
中,您的if
中有一個額外的點Cells.(e,d)
if
使用方括號 這應該工作正常:
Dim d As Integer
Dim e As Integer
For d = 1 To Range("PRcal").Columns.Count
For e = 1 To Range("PRcal").Rows.Count
If Range("PRcal").Cells(e, d).Value = Range("PRcal").Cells(1, d).Value Then
Cells(e, d).Value = Cells(e, 1)
End If
Next e
Next d
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.