Rowcounts value +1 doesnt work

Endered5

New Member
Joined
Oct 3, 2020
Messages
25
Office Version
  1. 2016
Hi.

Need help with rowcount value that I want to add on specific cells. For example if the text in column B starting from a specific place, finding "car, cat or horse" I want it to go on the same row, A column and write the next value. So it will be 1, 2, 3, 4, 5 and so on.

But it seems like that it wont write the value of "Cells(rowcounts + 1, 1).Value". Nothing happens. Why?
Please see below.



Dim rowcount10 As Integer
Dim rowcount11 As Integer
Dim rowcount12 As integer

rowcount10 = Cells(Rows.Count, 1).End(xlUp).Row
rowcount11 = Cells(Rows.Count, 2).End(xlUp).Row

For I = rowcount10 To rowcount11

rowcount12 = Cells(Rows.Count, 1).End(xlUp).Row

Cells(I + 1, 2).Select

If InStr(1, Range("B" & I + 1), "Car") Or InStr(1, Range("B" & I + 1), "Cat") Or InStr(1, Range("B" & I + 1), "Horse") Then

Cells(I + 1, 1).Value = Cells(rowcounts + 1, 1).Value

End If
Next I
 

Attachments

  • test2.JPG
    test2.JPG
    36.3 KB · Views: 2

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Dim rowcount10 As Integer
Dim rowcount11 As Integer
Dim rowcount12 As integer

rowcount10 = Cells(Rows.Count, 1).End(xlUp).Row
rowcount11 = Cells(Rows.Count, 2).End(xlUp).Row

For I = rowcount10 To rowcount11

rowcount12 = Cells(Rows.Count, 1).End(xlUp).Row

Cells(I + 1, 2).Select

If InStr(1, Range("B" & I + 1), "Car") Or InStr(1, Range("B" & I + 1), "Cat") Or InStr(1, Range("B" & I + 1), "Horse") Then

Cells(I + 1, 1).Value = Range("A" & rowcount12).value

End If
Next I
 
Upvote 0
So I want the value of ("A" & rowcount12) +1 added to my cell (Cells(I +1, 1). But it wont work
 
Upvote 0
How about
VBA Code:
Dim rowcount10 As Long, rowcount11 As Long, rowcount12 As Long, i As Long

rowcount10 = Cells(Rows.Count, 1).End(xlUp).Row
rowcount11 = Cells(Rows.Count, 2).End(xlUp).Row

For i = rowcount10 + 1 To rowcount11
   If InStr(1, Range("B" & i), "Car") Or InStr(1, Range("B" & i), "Cat") Or InStr(1, Range("B" & i), "Horse") Then
      rowcount12 = Cells(Rows.Count, 1).End(xlUp).Row
      Cells(i, 1).Value = Range("A" & rowcount12).Value + 1
   End If
Next i
 
Upvote 0
How about
VBA Code:
Dim rowcount10 As Long, rowcount11 As Long, rowcount12 As Long, i As Long

rowcount10 = Cells(Rows.Count, 1).End(xlUp).Row
rowcount11 = Cells(Rows.Count, 2).End(xlUp).Row

For i = rowcount10 + 1 To rowcount11
   If InStr(1, Range("B" & i), "Car") Or InStr(1, Range("B" & i), "Cat") Or InStr(1, Range("B" & i), "Horse") Then
      rowcount12 = Cells(Rows.Count, 1).End(xlUp).Row
      Cells(i, 1).Value = Range("A" & rowcount12).Value + 1
   End If
Next i
Thanks, it works great! Just one more question. How do I get back to my original cells(rowcount10, 1)? Since it is a loop the values in column A starts to fill, but after it ends I need to get back to the original A column, rowcount 10. Is it somehow possible?
 
Upvote 0
As the code doesn't select anything the active cell will never change.
So I'm not quite sure what you mean.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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