Interpretting Arrays

kate.middleton

New Member
Joined
Mar 24, 2012
Messages
31
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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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?
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,055
Latest member
excelhelp12345

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