VBA long or string byte-wise?

Dimitris254

Board Regular
Joined
Apr 25, 2016
Messages
139
i'm retrieving the cell color in a spreadsheet and assign it to a variable, then use the variable to color another cell.

Code:
color_1 = .Cells.Find(what:="mycell", LookIn:=xlValues, lookat:=xlWhole, SearchOrder:=xlByColumns).Interior.Color

.Cells(1, "A").Interior.Color = color_1

The code will work regardless if color_1 is Long or String (the color number is something like 10587882).

So, byte-wise, which one is smaller? :confused:
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I believe it would be Long.
A String could hold both more characters each character a full 32-bit word.
Long would be 1 32-bit word.
(or 64-bit word :confused:, either way same concept.)
 
Upvote 0
i'm retrieving the cell color in a spreadsheet and assign it to a variable, then use the variable to color another cell.

Code:
color_1 = .Cells.Find(what:="mycell", LookIn:=xlValues, lookat:=xlWhole, SearchOrder:=xlByColumns).Interior.Color

.Cells(1, "A").Interior.Color = color_1

The code will work regardless if color_1 is Long or String (the color number is something like 10587882).

So, byte-wise, which one is smaller? :confused:
It is not so much the byte size that matters (you have way more RAM than you could ever clog up with whichever is longer), rather, you should use Long because that is what the Color value is... if you use String, then VB has to waste execution cycles coercing the String value to a Long value in order to use it (and it would have to do that every time you used the variable in code if declared as a String). You should always make the variable declaration of the same type as the data that will be placed into it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,892
Members
449,194
Latest member
JayEggleton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top