ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Count backwards (https://www.excelbanter.com/excel-programming/365787-count-backwards.html)

leonidas[_30_]

Count backwards
 

Hi,

I have the following macro but it won't work, because, what I think
the backward counting "For i = 10 To 1" doesn't work.
Is there a solution for this problem so it can count backwards o
change the names of the ComboBoxes from 10 to 1 ? Thanks in advance!


Code
-------------------
Sub Test()

Dim ws As Worksheet
Dim i As Long

Set ws = ActiveSheet

For i = 10 To 1
Call LinkCombo(ws.OLEObjects("ComboBox" & i), "ComboBox" & i + 1)
Next i

End Sub
Private Sub LinkCombo(pCombo As OLEObject, pName As String)

With pCombo
.Name = pName
End With

End Su
-------------------

--
leonida
-----------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...fo&userid=3537
View this thread: http://www.excelforum.com/showthread.php?threadid=55686


RB Smissaert

Count backwards
 
Try:
For i = 10 To 1 Step -1

RBS

"leonidas" wrote in
message ...

Hi,

I have the following macro but it won't work, because, what I think,
the backward counting "For i = 10 To 1" doesn't work.
Is there a solution for this problem so it can count backwards or
change the names of the ComboBoxes from 10 to 1 ? Thanks in advance!


Code:
--------------------
Sub Test()

Dim ws As Worksheet
Dim i As Long

Set ws = ActiveSheet

For i = 10 To 1
Call LinkCombo(ws.OLEObjects("ComboBox" & i), "ComboBox" & i + 1)
Next i

End Sub
Private Sub LinkCombo(pCombo As OLEObject, pName As String)

With pCombo
.Name = pName
End With

End Sub
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile:
http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=556869



Andrew Taylor

Count backwards
 
You need:
For i = 10 to 1 Step -1

Andrew

leonidas wrote:
Hi,

I have the following macro but it won't work, because, what I think,
the backward counting "For i = 10 To 1" doesn't work.
Is there a solution for this problem so it can count backwards or
change the names of the ComboBoxes from 10 to 1 ? Thanks in advance!


Code:
--------------------
Sub Test()

Dim ws As Worksheet
Dim i As Long

Set ws = ActiveSheet

For i = 10 To 1
Call LinkCombo(ws.OLEObjects("ComboBox" & i), "ComboBox" & i + 1)
Next i

End Sub
Private Sub LinkCombo(pCombo As OLEObject, pName As String)

With pCombo
.Name = pName
End With

End Sub
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=556869



leonidas[_31_]

Count backwards
 

Hi,

Thank you both for the solution to my problem!
It works!
Thanks again

--
leonida
-----------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...fo&userid=3537
View this thread: http://www.excelforum.com/showthread.php?threadid=55686



All times are GMT +1. The time now is 12:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com