Hello Everyone,
I am using VBA for macros for use with an Excel spreadsheet I have been working on. The goal of the macro is to change 7th row's height to match that of a template.
In my first attempt I tried simply looping through the rows changing every seventh row's height and then moving on to the next one. Unfortunately, due to the size of the spreadsheet and other activities occurring at the same time, this became very inefficient. As an alternative I have already gathered a list of the rows to be changed in the following format into a string called Lst: "1:1,8:8,15:15,...,n:n" where n is the last row with data in it Then I use the string in the following line of code: - Range(Lst).RowHeight = Worksheets("Template").Range("A" & 1).RowHeight
Now this works until there is data in or past row 252. The sample I am using as a test has data until row 344. For this sample Lst should have the following value: "1:1,8:8,15:15,22:22,29:29,36:36,43:43,50:50,57:57 ,64:64,71:71,78:78,85:85,92:92,99:99,106:106,113:1 13,120:120,127:127,134:134,141:141,148:148,155:155 ,162:162,169:169,176:176,183:183,190:190,197:197,2 04:204,211:211,218:218,225:225,232:232,239:239,246 :246,253:253,260:260,267:267,274:274,281:281,288:2 88,295:295,302:302,309:309,316:316,323:323,330:330 ,337:337,344:344" To test the data I used MsgBox Lst, which does agree. To the contrary, the debugger which comes with Excel shows Lst to have the following value: "1:1,8:8,15:15,22:22,29:29,36:36,43:43,50:50,57:57 ,64:64,71:71,78:78,85:85,92:92,99:99,106:106,113:1 13,120:120,127:127,134:134,141:141,148:148,155:155 ,162:162,169:169,176:176,183:183,190:190,197:197,2 04:204,211:211,218:218,225:225,232:232,239:239,246 :246, Could someone help me resolve this issue? Thank you in advance.
SOLUTION - ** SNIP **
2 5400 NeoPa 32,556
Expert Mod 16PB
Although the string length can go into the millions, the string value passed as the Cell1 parameter to Range cannot exceed 256 without this failure occurring.
The following code will handle this if required, by breaking up the list of rows into strings which are each less than 256 long and setting the .RowHeight property for each one : - Option Explicit
-
-
Public Sub SetRowHeight(lngMaxRow As Long)
-
Dim strRows As String, strWork As String
-
Dim lngX As Long
-
Dim dblRowHeight As Double
-
-
dblRowHeight = Worksheets("Template").Range("A1").RowHeight
-
For lngX = 1 To lngMaxRow Step 7
-
strRows = strRows & Replace(",R:R", "R", lngX)
-
Next lngX
-
strRows = Mid(strRows, 2)
-
Do While strRows > ""
-
If Len(strRows) > 256 Then
-
lngX = InStr(240, strRows, ",") - 1
-
Else
-
lngX = Len(strRows)
-
End If
-
strWork = Left(strRows, lngX)
-
Range(strWork).RowHeight = dblRowHeight
-
strRows = Mid(strRows, lngX + 2)
-
Loop
-
End Sub
NeoPa 32,556
Expert Mod 16PB
I did try similar code but using the Union() method instead (See below), but it ran a great deal more slowly. - Option Explicit
-
-
Public Sub SetRowHeight(lngMaxRow As Long)
-
Dim strRows As String, strWork As String
-
Dim lngX As Long
-
Dim ranList As Range
-
-
Set ranList = Range("1:1")
-
For lngX = 8 To lngMaxRow Step 7
-
strRows = strRows & Replace(",R:R", "R", lngX)
-
Next lngX
-
strRows = Mid(strRows, 2)
-
Do While strRows > ""
-
If Len(strRows) > 256 Then
-
lngX = InStr(240, strRows, ",") - 1
-
Else
-
lngX = Len(strRows)
-
End If
-
strWork = Left(strRows, lngX)
-
Set ranList = Union(ranList, Range(strWork))
-
strRows = Mid(strRows, lngX + 2)
-
Loop
-
ranList.RowHeight = Worksheets("Template").Range("A1").RowHeight
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Harald Massa |
last post by:
which one should I use? Recommendations?
Harald
|
by: Adrian Albisser |
last post by:
Hey to everybody, im just beginning to program in python. So i was trying
some function but always when i try the range function i get a error
message.
for number in range(1,100):
print number...
|
by: bwooster47 |
last post by:
I'm a newcomer to python - what is the best way to convert a list into
a function call agruments?
For example:
list = (2005, 5, 5)
date = datetime.date( list )
fails with:
TypeError:...
|
by: Xah Lee |
last post by:
Today we'll be writing a function called Range. The Perl documentation
is as follows.
Perl & Python & Java Solutions will be posted in 48 hours.
This is Perl-Python a-day. See...
|
by: Chris |
last post by:
Hey all. Anyone who is familiar with Python programming knows that you
can have code like this:
list =
This code puts all the items processed by the for loop in a list plus
1. Is there a way...
|
by: Summercoolness |
last post by:
it seems that range() can be really slow:
the following program will run, and the last line shows how long it ran
for:
import time
startTime = time.time()
a = 1.0
|
by: thattommyhallll |
last post by:
i am doing the problems at
http://www.mathschallenge.net/index.php?section=project
one problem involved finding factors, i used
def divisors(n):
divisors = set()
for i in range(1, math.ceil(n...
|
by: bibaudj |
last post by:
I'm trying to write a function to be used in a query - because I don't think it can be compiled directly in a query (using Expression Builder). This is for a holiday DB. I would like to determine...
|
by: vimal |
last post by:
hi all,
i am new to python.....
i just want to generate numbers in the form like:
1,2,4,8,16,32.....to a maximum of 1024
using a range function
|
by: John Salerno |
last post by:
I know it's popular and very handy, but I'm curious if there are purists
out there who think that using something like:
for x in range(10):
#do something 10 times
is unPythonic. The reason I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |