Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dear Bob I have noticed that it is only generating the error on certain
rows, if i run it on a row it will work fine, but then if i run it on some other row it generates the problem. I've included the full code for the macro i'm using here, which the code you gave me was a part of. Could you please take a look and see where you think it might be going wrong? ..... Sub SelectEveryThird() Dim ilastcolumn As Long Dim textstring As String Application.ScreenUpdating = False ilastcolumn = (Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Column) ' 42 is the number of columns between repeated fields. ' 6 is the numberical reference for the first column that contains make data. model = 7 expirary = 38 commision = 42 For make = 6 To ilastcolumn Step 42 With ActiveCell sMake = Cells(.Row, make).Value sModel = Cells(.Row, model).Value sExpiry = Cells(.Row, expirary).Value sCommission = Cells(.Row, commision).Value textstring = sMake & Space(20 - Len(sMake)) & " - " & _ sModel & Space(30 - Len(sModel)) & " - " & _ sExpiry & Space(30 - Len(sExpiry)) & " - " & _ "£" & sCommission & Space(30 - Len(sCommission)) & _ Chr(10) End With If model + 42 = ilastcolumn Then model = ilastcolumn Else model = model + 42 End If If expirary + 42 = ilastcolumn Then k = expirary Else expirary = expirary + 42 End If If commision + 42 = ilastcolumn Then commision = ilastcolumn Else commision = commision + 42 End If Next make Cells(ActiveCell.Row, "A").Value = textstring End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The only thing to note is that the textstring= in the code I use starts
textstring= textring & .. because i'm compiling a list of order data. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have figured out the problem, the 20, and 30 for the spaces were not
long enough so were generating negative spacing for high value strings. Having fixed this i have one final hurdle. The above code is not creating a list of data, instead it is creating only one line of data into Cell A. I had though that by having textstring = textstring & ... that the textstring would increase by the size of the newest textstring at each interation but for some reason i'm only getting one line of data, regardless of the number of columns? Many Thanks, Gary. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorted. I had misspelled the variable.
It's working like a gem now. Thanks to both of you! All the best, Gary |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Data Validation, Need text any length no spaces | Excel Discussion (Misc queries) | |||
number as string and adding spaces to it | Excel Programming | |||
Counting string length | Excel Programming | |||
counting spaces in a string | Excel Programming | |||
counting spaces in a string | Excel Programming |