Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


all combination of varibale number of numbers


all combination of varibale number of numbers

Author
Message
sheila
sheila
Forum God
Forum God (523 reputation)Forum God (523 reputation)Forum God (523 reputation)Forum God (523 reputation)Forum God (523 reputation)Forum God (523 reputation)Forum God (523 reputation)Forum God (523 reputation)Forum God (523 reputation)

Group: Forum Members
Posts: 1, Visits: 8
Hi all

my code give me all combination of any number of numbers except all 4 digit combination of 6 numbers for exmaple:



1-3-5-6 this is my code in blow



Sub test2()



Dim bar, a1, a3, a4, mot1, rowcount1 As Integer Dim s1 As String



Range("d1:d100").ClearContents



mot1 = 0



rowcount1 = 6



For bar = 1 To rowcount1 - 1

For a1 = 1 To rowcount1 - bar

For a3 = 1 To a1

mot1 = mot1 + 1 Cells(mot1, 4) = Cells(a3, 3)



For a4 = 1 To bar



s1 = ((a1 + a4)) Cells(mot1, 4) = Cells(mot1, 4) & "-" & Cells(s1, 3)



Next a4

Next a3

Next a1

Next bar



End Sub

please help to edit my code :-(
bawldiggle
bawldiggle
Forum God
Forum God (511 reputation)Forum God (511 reputation)Forum God (511 reputation)Forum God (511 reputation)Forum God (511 reputation)Forum God (511 reputation)Forum God (511 reputation)Forum God (511 reputation)Forum God (511 reputation)

Group: Forum Members
Posts: 1, Visits: 2
@ sheila

I know there have been a lot of lookers (to date) and maybe too late for Sheila ... but this post is for late comers



You have declared possible cell addresses a Variants

ie, a1, a3, a4, s1 ... as Variants are interpreted by VBA as cell objects

- VBA assumes strings that look like a cell address are in fact Objects (of absolute reference) not variables



Best practice is to always to head up modules with "Option Explicit" so that you are forced to declare Variables by a specific data type.

- and never create variable names that can be misinterpreted by VBA as objects

eg, Sheet1, A1, B53... might be misinterpreted by VBA as literal objects on the active worksheet



If variables are not explicitly declared as specific data types you are setting yourself up to trip up.



Variable names are better constructed so that others can follow your intentions and for your own clarity in 2 or 3 years time.

examples:

Dim strName As String

Dim objOneCell as Object

Dim objShtRead As Sheet

Dim objShtWrite As Sheet

Dim intNumber As Integer

Dim a As Integer

Dim cc as Long



Smile



Edited
10/2/2015 by bawldiggle
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search