Help: Basic VB Function for Excel

Drajakur

Molten Core Raider
562
452
Hi folks. I'm wondering if one of you could help me out with a task that is totally outside my realm of expertise. What I need is a way to automate the following formula in Excel:

=DEC2HEX(HEX2DEC(MyNum1)+HEX2DEC(NyNum2))

Where the user is given the option to select a cell to determine MyNum1 and MyNum2 (in other words, to treat these as variables that a user defines when running the formula). What I'm doing at the moment is selecting a cell where this formula is being used, copying it, pasting it into another bunch of other cells, and then manually editing the cells by hand to refer to the correct values. That is just retardedly clumsy.

God I would appreciate any help.
 

The Ancient_sl

shitlord
7,386
16
How many options for cell selection are you needed? You may not need VB for it, just a designated "selection" cell and a named group.
 

Noodleface

A Mod Real Quick
37,961
14,508
Maybe this is a dumb question but why are you converting two numbers to decimal to add them then converting back to hex? Hex is just a representation of a binary string (and decimal is as well). Seems like there is no need for it.. humor me if I am retarded.
 

The Ancient_sl

shitlord
7,386
16
Excel's '+' works with decimals. If I asked it what C+C was it'd go "what, you crazy?" not 18.

This is common sense though, since a hexadecimal number can look exactly like a decimal and hold a different value, how would the program know what to add?
 

Noodleface

A Mod Real Quick
37,961
14,508
Oh ok, didn't know the + worked with decimals, just curious. Are you talking about something like 0x10 not being the same as 10? Ive never used excel for hex.
 

Drajakur

Molten Core Raider
562
452
Hi guys. Thanks for the responses/interest.

Yeah, Excel can't work functions on HEX numbers natively. So you have to convert them to DEC, perform the function, and then convert them back to HEX. If you had asked me this before I discovered it, I would have thought you were crazy because I assumed there was just some way to say "this worksheet is base-16". But there isn't. Even now, Excel STILL treats some HEX values as Scientific Notation until you format the cells accordingly. Oh, and by the way, it can only calculate HEX to 10 characters. Anything else returns an error (although it can, of course, calculate the DEC equivalent easily).

Ancient - sadly, the scope of variables numbers in the thousands of cells (4 kinds of memory (cached, uncached, virtual, physical), 32-bit start and end addresses, plus variable offset depending on one of X masters, for a large number of slaves).

I would never be doing this in Excel voluntarily, but I was given this mass of existing data to work with and, well, this is the hand I've been dealt...
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
I would never be doing this in Excel voluntarily, but I was given this mass of existing data to work with and, well, this is the hand I've been dealt...
Shouldn't be anything stopping you from saving the worksheet as a .csv delimited by <whatever> and importing it into something else. It sounds like this could be a better way of doing the job than using Excel. I guess the question at hand is: What would you rather be doing this with/in, and is the only acceptable answer one that uses Excel?

Edit: In any case, it should be as simple as typing it out (e.g. =DEC2HEX(HEX2DEC(A1) + HEX2DEC(B1)) ), click dragging the + symbol by clicking on the bottom right of the cell and dragging it all the way down the worksheet. That'll automatically apply the formula to the entire worksheet as long as the values are organized row-by-row in separate columns. Like this:1234

Sorry if I'm oversimplifying this. No sample set of data or anything, but even if it's more complicated than that, the premise should remain the same unless I'm missing something here...
 

Drajakur

Molten Core Raider
562
452
Shouldn't be anything stopping you from saving the worksheet as a .csv delimited by <whatever> and importing it into something else. It sounds like this could be a better way of doing the job than using Excel. I guess the question at hand is: What would you rather be doing this with/in, and is the only acceptable answer one that uses Excel?

Edit: In any case, it should be as simple as typing it out (e.g. =DEC2HEX(HEX2DEC(A1) + HEX2DEC(B1)) ), click dragging the + symbol by clicking on the bottom right of the cell and dragging it all the way down the worksheet. That'll automatically apply the formula to the entire worksheet as long as the values are organized row-by-row in separate columns. Like this:1234

Sorry if I'm oversimplifying this. No sample set of data or anything, but even if it's more complicated than that, the premise should remain the same unless I'm missing something here...
Well, your first point hits on an added complexity I didn't mention. Ultimately, I have to output all this data as XML, and I can do that easily in Excel. The XML tools I have access too at the office are way too clunky for complex worksheets so, yeah, in that regard using Excel is pretty much the only option. I should also mention that the company where I'm working hates investing in new tools, so the chances of me being able to secure budget for New Tool X is slim to none.

Unfortunately, your proposed solution doesn't work because, yes, the data is more complicated than that. Some of the memory regions in a series of rows use the same offset, so making the formula sequential doesn't work for them (I have to go back and edit so that multiple rows refer to the same cell); and some of the columns for base memory addresses are in different worksheets. I could probably get around the second issue by restructuring the worksheets, but I'm loathe to do that since the engineers are already familiar with the existing format and, to be blunt, are likely to push back against using a totally new arrangement. I should also add that there is a logical reason to organize the data in the existing way, it just happens to make my particular task less efficient.

Radically simplified, the data looks like this:

Worksheet 1: Masters (Region Name, Start, End)
Region_1 00000000 0000FFFF
Region_2 0FFF1111 0FFFFFFF

Worksheet 2: Offsets (Name, Mask)
Region_1 C0000000
Region_2 A0000000

Worksheet 3: Results in XML (Name, Calculated Start, Calculated End)
Region_1 C0000000 C000FFFF
Region_2 AFFF1111 AFFFFFFF

Just note that in the real data Region_1 and Region_2 might be 27 or whatever rows apart, and there are 6+ masters that use the same offset but different base regions, and there are 4 types of start/end address for each row. Maybe the following capture will help...
 

The Ancient_sl

shitlord
7,386
16
So all your data is properly labeled? Why can't you use vlookup or match to determine the proper cell to calculate from? You know how to use indirect() to create a cell reference, right?
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
Yeah, sounds like you might have to massage the data a bit to make it easier on yourself. If you have the same name as a key (e.g. Region and PHY/Description), it shouldn't be too hard to create a new worksheet that combines the two tables and sets up an easier way for you to reference the data (e.g. creating two rows for the example you gave above -- one that indicates 4000000 + 0FFFFFFF and one that indicates 40000000 + EFFFFFFF, or one row with all three numbers in it that can use two copies of the formula with predictable cell numbers, or... there are a lot of ways to do this).

I'm working on about 1 hour of sleep here or I'd try to do this myself. Sorry. I was up all night taking care of my very pregnant wife. Training for baby starts now, apparently...

Good luck!