LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Counting the length of a string and adding spaces...

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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation, Need text any length no spaces BB Excel Discussion (Misc queries) 5 August 8th 07 12:46 PM
number as string and adding spaces to it A.New Excel Programming 2 January 26th 05 03:22 AM
Counting string length The Wonder Thing[_3_] Excel Programming 4 August 3rd 04 09:23 PM
counting spaces in a string xnman Excel Programming 7 May 9th 04 03:06 PM
counting spaces in a string xnman Excel Programming 4 December 16th 03 01:36 AM


All times are GMT +1. The time now is 04:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"