Change all values in column E between two rows?

mir994stan

New Member
Joined
Jul 18, 2021
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
Hello again, somehow i menage to deal wth my data entry problem, with some help from Indian youtubers. But i couldn t find any similar post. Is it possible to make a macro to change Status from "On Stock" to "Sent" in column E for all rows between two ID number, where are found given values. For example in row 15 is ID number is 6000250-15 and in row 30 is ID 6000250-30, i need to change status for all IDs in between, including starting and ending number. From Combox1 i would choose worksheet where specific ID is stored and in textbox1 and textbox2 i would enter ID numbers for search, Textbox3 contain Status value and TextBox4 =today(). And Cmdbutton 1 to run that macro. Hope that somebody can help, or at least give me some hint where/what to search. Many thanks in advace. Link: Screen shot example
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
1627606025791.png

That is your example of the image.
From Combox1 i would choose worksheet where specific ID is stored and in textbox1 and textbox2 i would enter ID numbers for search, Textbox3 contain Status value and TextBox4 =today().

Based on that image. What data do you have in the combo, in textbox1, textbox2, textbox3, textbox4 and what should the VBA code do?
 
Upvote 0
STATUS SAMPLE.PNG

Im sorry for my poor explanation, in this image is my userform and data from one of the worksheets, ComboBox1 is "Name of product" and it have all worksheet names, i have worksheets for each product. And when i select a value from dropdown list, in that sheet i want to change status for given values by criteria in textbox1 and textbox2. Textbox1 "First number" and Textbox2 "LastNumber" are empty by default, i thought to write in them for which range of Serial numbers i need to change status in column "E", Combobox2 only contain two values "On Stock" and "Sent", Textbox3 needs to write date of status change in column "G". I hope this can explain what i want to achive.
 
Upvote 0
Try this

VBA Code:
Private Sub CommandButton1_Click()
  Dim i As Long
  For i = 1 To Range("A" & Rows.Count).End(3).Row
    If Range("B" & i).Value = ComboBox1 And _
      Range("A" & i).Value >= TextBox1 And Range("A" & i).Value <= TextBox2 Then
      Range("E" & i).Value = ComboBox2
      Range("F" & i).Value = TextBox3
    End If
  Next
End Sub
 
Upvote 0
Solution
Try this

VBA Code:
Private Sub CommandButton1_Click()
  Dim i As Long
  For i = 1 To Range("A" & Rows.Count).End(3).Row
    If Range("B" & i).Value = ComboBox1 And _
      Range("A" & i).Value >= TextBox1 And Range("A" & i).Value <= TextBox2 Then
      Range("E" & i).Value = ComboBox2
      Range("F" & i).Value = TextBox3
    End If
  Next
End Sub

[/C
[/QUOTE]
Works as expected. A few lines of code saved me big time searching and replacing manualy. Thank you Sir.
 
Upvote 0
Hello Dante,
I noticed i have a small problem with your code from this question, and i have no idea how to fix this. Can u give me some suggestions? As u can see in image below, code for some reason skip changing values in some rows. All values in each column are in same format. I painted red values that are skiped from change from U magacinu (On Stock) to Sent? And that happend sometimes, most of the time code runs as expected. Thank you in advance! Mirko
Capture.PNG
 
Upvote 0
We did the tests with
60188-01
60188-02
...
But now you used:
60188-1
60188-2
And it's not the same.

Try the following:

VBA Code:
Private Sub CommandButton1_Click()
  Dim i As Long
  Dim part1 As String, x1 As String, y1 As String
  Dim part2 As Long, x2 As Long, y2 As Long
  
  For i = 1 To Range("A" & Rows.Count).End(3).Row
    If Range("B" & i).Value = ComboBox1 Then
      If InStr(1, Range("A" & i).Value, "-") > 0 Then
        x1 = Split(TextBox1, "-")(0)
        x2 = Split(TextBox1, "-")(1)
        y1 = Split(TextBox2, "-")(0)
        y2 = Split(TextBox2, "-")(1)
        part1 = Split(Range("A" & i).Value, "-")(0)
        part2 = Val(Split(Range("A" & i).Value, "-")(1))
        If part1 = x1 Or part1 = y1 Then
          If part2 >= x2 And part2 <= y2 Then
            Range("E" & i).Value = ComboBox2
            Range("F" & i).Value = TextBox3
          End If
        End If
      End If
    End If
  Next
End Sub
 
Upvote 0
Oh sorry, i didn t know that... Great, its working, thank you for your time and help a lot! God bless you!
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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