Esmannitor
New Member
- Joined
- May 23, 2015
- Messages
- 8
Hi,
I am doing an assignment in IT. I don't have that much experience in VBA, so my code below is pretty primitive. I have some troubles with the If statements. I want to count the number of times the If statement is True and bind it to "CountL". So in my assignment as shown below, I want it to search through column 2 to last column and then if there are any cells with "L" as the first character, then it should count it and add it to the CountL, so I can use it later depending on the value.
What is the best way to do this?
Dim AddRow As Integer
With ws.Range("A:A")
Set FindAddRow = .Find(ProjektComboBox2.Value, LookIn:=xlValues)
If Not FindAddRow Is Nothing Then
firstAddress = FindAddRow.Address
Do
AddRow = FindAddRow.Row
Set FindAddRowj = .FindNext(FindAddRow)
Loop While Not FindAddRow Is Nothing And FindAddRow.Address <> firstAddress
End If
End With
Dim LastColumn As Integer
Dim CountL As Integer
LastColumn = WorksheetFunction.CountA(Range("2:2"))
For Target_Cells = 2 To LastColumn
If Left(Range(Cells(AddRow, Target_Cells), Cells(AddRow, Target_Cells)), 1) = "L" Then
CountL = Count(Upper statement = True)
MsgBox "A projectleader do already exist for this project."
End If
Next Target_Cells
Thank you in advance!
I am doing an assignment in IT. I don't have that much experience in VBA, so my code below is pretty primitive. I have some troubles with the If statements. I want to count the number of times the If statement is True and bind it to "CountL". So in my assignment as shown below, I want it to search through column 2 to last column and then if there are any cells with "L" as the first character, then it should count it and add it to the CountL, so I can use it later depending on the value.
What is the best way to do this?
Dim AddRow As Integer
With ws.Range("A:A")
Set FindAddRow = .Find(ProjektComboBox2.Value, LookIn:=xlValues)
If Not FindAddRow Is Nothing Then
firstAddress = FindAddRow.Address
Do
AddRow = FindAddRow.Row
Set FindAddRowj = .FindNext(FindAddRow)
Loop While Not FindAddRow Is Nothing And FindAddRow.Address <> firstAddress
End If
End With
Dim LastColumn As Integer
Dim CountL As Integer
LastColumn = WorksheetFunction.CountA(Range("2:2"))
For Target_Cells = 2 To LastColumn
If Left(Range(Cells(AddRow, Target_Cells), Cells(AddRow, Target_Cells)), 1) = "L" Then
CountL = Count(Upper statement = True)
MsgBox "A projectleader do already exist for this project."
End If
Next Target_Cells
Thank you in advance!