If only run first line and skip the others

Capa7md

New Member
Joined
Aug 21, 2023
Messages
11
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi i want ti edit my data by using if and when i run the code it just go to first line and skip the others

Private Sub CommandButton1_Click()
Dim LastRow As Long
Dim NewRow As Long
LastRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For NewRow = 3 To LastRow
If Sheet1.Cells(NewRow, 1) = CInt(Me.TextBox6) Then
Sheet1.Cells(NewRow, 2) = Me.TextBox1
Sheet1.Cells(NewRow, 3) = Me.TextBox2
End If
Next NewRow



End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Dim userin As Long
userin = Me.ListBox1.ListIndex
Me.TextBox6 = Me.ListBox1.List(userin, 0)
Me.TextBox1 = Me.ListBox1.List(userin, 1)
Me.TextBox2 = Me.ListBox1.List(userin, 2)``
Me.ComboBox1 = Me.ListBox1.List(userin, 3)
Me.ComboBox2 = Me.ListBox1.List(userin, 4)
Me.TextBox3 = Me.ListBox1.List(userin, 5)
Me.TextBox4 = Me.ListBox1.List(userin, 6)
Me.ComboBox3 = Me.ListBox1.List(userin, 7)
end sub
and this code to try to comper 2 values to fint the row to let the user to edit data
Private Sub CommandButton1_Click()
Dim LastRow As Long
Dim NewRow As Long
LastRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For NewRow = 3 To LastRow
If Sheet1.Cells(NewRow, 1) = CInt(Me.TextBox6) Then
Sheet1.Cells(NewRow, 2) = Me.TextBox1
Sheet1.Cells(NewRow, 3) = Me.TextBox2
End If
Next NewRow
End Sub
~~~
 
Upvote 0
Sorry Capa7md I can't help you with your code because it works for me.

Here the code jump to next sub
if you mean jumps to Next NewRow,
that is what it will do for every row from 3 to LastRow where the "A" Column value doesn't equal TextBox6 value.

If I understand what you say in post #5 that Column "A" cells have formula =Row() and
TextBox6 is the row you want to work on, why not work on the row directly?
VBA Code:
Private Sub CommandButton1_Click()
    Sheet1.Cells(Me.TextBox6.Value, 2) = Me.TextBox1
    Sheet1.Cells(Me.TextBox6.Value, 3) = Me.TextBox2
End Sub
 
Upvote 0
Sorry Capa7md I can't help you with your code because it works for me.


if you mean jumps to Next NewRow,
that is what it will do for every row from 3 to LastRow where the "A" Column value doesn't equal TextBox6 value.

If I understand what you say in post #5 that Column "A" cells have formula =Row() and
TextBox6 is the row you want to work on, why not work on the row directly?
VBA Code:
Private Sub CommandButton1_Click()
    Sheet1.Cells(Me.TextBox6.Value, 2) = Me.TextBox1
    Sheet1.Cells(Me.TextBox6.Value, 3) = Me.TextBox2
End Sub
my data start from row 3 . textbox6 and column A take “=row()-2” to hold serial number .
I am using if to get row number if tow value in text6 and column A is equal and the condition is true my problem is the code only run the first line in if
 
Upvote 0
That picture indicates the IF statement TRUE for the following lines to be executed.
Glad you got it sorted.
 
Upvote 0
That picture indicates the IF statement TRUE for the following lines to be executed.
Glad you got it sorted.
My main issue is the if statement only run on the first line of if code and the rest will be skipped
 
Upvote 0
In that case I'm afraid I don't have a clue what you're talking about, sorry.
 
Upvote 0
@Capa7md , when you step through your code, just before the IF statement executes, what are the Values of NewRow and LastRow?
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,643
Members
452,992
Latest member
TokugawaIesuma

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