identify with 1 when a line string value change ignoring empty cells

JoaoGabriel

New Member
Joined
Jun 6, 2021
Messages
15
Office Version
  1. 2019
Platform
  1. Windows
I'm trying to create a macro that identifies with 1 when there is a change in row values and 0 when there isn't. Ignoring blank cells in both cases.
The data looks like this:
excel.png



I got the following macro, but I couldn't ignore blank values and apply to multiple lines at once

VBA Code:
Sub ValueChange()
Dim curR As Range
Set curR = Application.Selection
Set curR = Application.InputBox("Select the Range of Cells", xTitleId, curR.Address, Type:=8)
curR.Cells(1, 13).Value = 0

For i = curR.Columns.Count To 2 Step -1
    If curR.Cells(1, i).Value <> curR.Cells(1, i - 1).Value Then
        curR.Cells(1, 13).Value = 1
    End If
Next

End Sub

Can anyone help?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Give this macro a try (it will process all your data without you needing to select anything)...
VBA Code:
Sub IsAllTheSame()
  Dim R As Long, LastRow As Long, Arr As Variant
  LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  For R = 2 To LastRow
    Arr = Split(Application.Trim(Join(Application.Index(Cells(R, "B").Resize(, 12).Value, 1, 0))), , 2)
    Cells(R, "N").Value = -(Len(Trim(Replace(Arr(1), Arr(0), ""))) > 0)
  Next
End Sub
 
Upvote 0
Give this macro a try (it will process all your data without you needing to select anything)...
VBA Code:
Sub IsAllTheSame()
  Dim R As Long, LastRow As Long, Arr As Variant
  LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  For R = 2 To LastRow
    Arr = Split(Application.Trim(Join(Application.Index(Cells(R, "B").Resize(, 12).Value, 1, 0))), , 2)
    Cells(R, "N").Value = -(Len(Trim(Replace(Arr(1), Arr(0), ""))) > 0)
  Next
End Sub
Thanks for taking the time to look at this for me - works brilliantly well thank you!
 
Upvote 0
Give this macro a try (it will process all your data without you needing to select anything)...
VBA Code:
Sub IsAllTheSame()
  Dim R As Long, LastRow As Long, Arr As Variant
  LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  For R = 2 To LastRow
    Arr = Split(Application.Trim(Join(Application.Index(Cells(R, "B").Resize(, 12).Value, 1, 0))), , 2)
    Cells(R, "N").Value = -(Len(Trim(Replace(Arr(1), Arr(0), ""))) > 0)
  Next
End Sub

Sorry to ask again, but when the data have just one value in the row the macro stops. How can i avoid this and put a 0 because there was no change in the same row?

CHANGE.png
 
Upvote 0
Give this version a try...
VBA Code:
Sub IsAllTheSame()
  Dim R As Long, LastRow As Long, Arr As Variant
  LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  For R = 2 To LastRow
    Arr = Split(Application.Trim(Join(Application.Index(Cells(R, "B").Resize(, 12).Value, 1, 0))) & " ", , 2)
    Cells(R, "N").Value = -(Len(Trim(Replace(Arr(1), Arr(0), ""))) > 0)
  Next
End Sub
 
Upvote 0
Give this version a try...
VBA Code:
Sub IsAllTheSame()
  Dim R As Long, LastRow As Long, Arr As Variant
  LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  For R = 2 To LastRow
    Arr = Split(Application.Trim(Join(Application.Index(Cells(R, "B").Resize(, 12).Value, 1, 0))) & " ", , 2)
    Cells(R, "N").Value = -(Len(Trim(Replace(Arr(1), Arr(0), ""))) > 0)
  Next
End Sub

Thank you so much, it worked perfectly
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

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