Interpretting Arrays

kate.middleton

New Member
Hello Everybody,

I have a Data in Column A something like This,
567
567
567
789
654
321

In this case it opens the word document write 567, 3 times then close it. Then again open the same word doc write 789, 1 time then close and so on. I am fail to make the logic in if Else Statement. Your help will be appreciated.

Code:
``````Sub Test()

Dim Counter_Start   As Integer
Counter_Start = 2

Dim Counter_End         As Integer
Counter_End = ThisWorkbook.Sheets(1).Range("A65536").End(xlUp).Row

Dim Number_Array()                 As String
ReDim Number_Array(2 To Counter_End)

For iCounter = Counter_Start To Counter_End
Number_Array(iCounter) = ThisWorkbook.Sheets(1).Range("A" & iCounter).Value
Next iCounter
Number_Array_Preserve = Number_Array

str_Word = "H:\MAKROS\Test.docx"
Set obj_Word = GetObject(str_Word)
Set rngWord = obj_Word.Content

'''''From Here i am unable to make logic, I want that when the value gets change in column A then it write the values somewhere in word document.
For iCounter = Counter_Start To Counter_End
If Number_Array(iCounter) = Number_Array(iCounter + 1) Then

ElseIf Number_Array(iCounter) <> Number_Array(iCounter + 1) Then
iCounter = iCounter + 1
End If
Next iCounter

End Sub``````

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

crewaustin66

Board Regular
So you're dealing with a control break situation. In a sorted list, when a value changes, do something.

Code:
``````Dim lastVal as string
Dim curVal as string
lastval = "": curVal = ""
For iCounter = Counter_Start To Counter_End
curVal = Number_Array(iCounter)
if curVal <> lastVal then
' do something
lastVal = curVal
end if
Next iCounter``````

Something like this perhaps?

Replies
9
Views
2K
Replies
0
Views
1K
Replies
3
Views
438
Replies
1
Views
829
Replies
1
Views
410

1,191,552
Messages
5,987,232
Members
440,086
Latest member
Mahi786

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.

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

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