How do I say if named cell exist then copy it to cell A2 otherwise do nothing - copy

I am trying to create a macro to copy named cells I am interested in from one location to another for example:
Sheets("QAreport").Select
Range("Noise").Select
Selection.Copy
Sheets("Trend2").Select
Range("G2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _:=False, Transpose:=False
But the named cells in my macro won't always exist so I need to say if it exists copy it to the specified location, otherwise do nothing.
Any help/tips would be appreciated
I have searched online and asked friends how to do this but I have not found the answer to this.

Related

Finding the Name of a Range using VBA

Using VBA, how do you find the name of the range of an active cell (merged cells)? I have a worksheet that I have established a few named ranges. i.e. K7:R28 is a range of merged cells and is named "LocM11". I typed that into the Name box and it is already established. In my VBA code, if a user clicks on the merged cells of K7:R28 and presses a command button I want the code to return the name "LocM11" and save it as a variable to be used later in the code. I've looked everywhere but this has me stumped. Any advice is appreciated.
I've tried some code sniplets I found on the internet to no avail. I've found code that uses VBA to name a range, but I do not want to do that. I have the name established. I want to know the already existing Name and save it as a variable.
try this
Dim activeRange As Range
Dim rangeName As String
Set activeRange = ActiveCell.Range
rangeName = Application.Range(activeRange.Address).Name
Debug.Print rangeName
More details - https://learn.microsoft.com/en-us/office/vba/api/excel.application.range#example

How to set a name for the cell

I have a cell array. when I want create a cell array that its name is : '0691008752' in this case an error :"Invalid field name"
cellUsers.('0691008752') = ....
I know the reason for this error is that a number is called. But I do not know how I can set this name for the cell.
I agree with the comments above, prepending the field with a letter is the best solution for this problem..
One way to make this consistent is to use:
fname = matlab.lang.makeValidName('0691008752')
Its not widely known but you can have fields which begin with number - its bad practice and will almost certainly leads to bugs....
So how to do it, 1st you need to use mex, if you see the mathworks mex example and modify the appropriate line:
memcpy(fieldnames[0],"Doublestuff",sizeof("Doublestuff"));
to:
memcpy(fieldnames[0],"01234",sizeof("01234"));
After compiling and running you get:
Note: You can only access it through dynamic fields names. To update the field you must use mex.

** No sls-discount record is available. (91)

/*
sls-discount i sthe database name
*/Good day. I have another problem in regards again to value change of a specific browse.
my code for Add Button:
FIND CURRENT {&FIRST-TABLE-IN-QUERY-DIALOG-FRAME} NO-LOCK NO-ERROR.
IF AVAIL {&FIRST-TABLE-IN-QUERY-DIALOG-FRAME} THEN DO:
ASSIGN mode = 3.
ASSIGN BROWSE BROWSE-13:READ-ONLY = NO
sls-discount.dsc-amount:READ-ONLY IN BROWSE BROWSE-13 = NO
sls-discount.dsc-discount:READ-ONLY IN BROWSE BROWSE-13 = NO
sls-discount.log:READ-ONLY IN BROWSE BROWSE-13 = NO.
{&OPEN-QUERY-BROWSE-13}
IF BROWSE-13:num-iterations ne 0 then
BROWSE BROWSE-13:SELECT-FOCUSED-ROW().
BROWSE BROWSE-13:INSERT-ROW("BEFORE"). /*will cause value-change in browse*/
APPLY 'entry' TO sls-discount.dsc-discount IN BROWSE BROWSE-13.
RUN disp-enable.
END.
my code for browse-13:
ASSIGN xpromo-no = {&FIRST-TABLE-IN-QUERY-BROWSE-13}.promo-no
mdlrid = {&FIRST-TABLE-IN-QUERY-BROWSE-13}.record-id.
MESSAGE xpromo-no mdlrid VIEW-AS ALERT-BOX INFO.
OPEN QUERY BROWSE-16 FOR EACH sls.sls-disccount-model WHERE sls.sls-disccount-model.promo-no = xpromo-no
AND sls.sls-disccount-model.record-id = mdlrid NO-LOCK,
EACH sls.sls-model WHERE sls.sls-model.car-model = sls.sls-disccount-model.car-model NO-LOCK.
if I uncomment the entire value-change in a browse, it will display the message "** No DBName record is available. (91)" when clicking the add button. but if commented/removed, it will not display the message.
hope you can help me again .. Thanks
You've doubtless run into the infamous "partial field auto-completion" feature / bug. What that means is - if you cite a variable with no local definition for it, the Progress compiler will search all the available tables for a field that starts with the same sequence of letters and use that instead.
What the error is telling you is that the compiler associated a field with something in the "DBName" table, and when the code tries to access that variable, the DBName buffer isn't in scope - which is understandable since accessing it wasn't your intention.
My guess is that you've mis-specified a BROWSE construct. Looking at your first set of constructs, you've got two different forms:
BROWSE BROWSE-13:READ-ONLY = NO
sls-discount.dsc-amount:READ-ONLY IN BROWSE BROWSE-13 = NO
I'll bet one of these is wrong, and the compiler is associating the illegal "browse" citation with a field in DBName that starts with "Browse".
If you compile the code to an XREF file, it'll tell you which variable it's trying to associate with the DBName table. Correct that, and you'll be good to go.
I figure out what the problem on the code.. on click of Add button, the row inside browse-13 was arrange because of the {&OPEN-QUERY-BROWSE-13}. after that, because of BROWSE BROWSE-13:SELECT-FOCUSED-ROW(), it focused on the TOP date on browse and last, BROWSE BROWSE-13:INSERT-ROW("BEFORE"), created a blank data row at the very top. thus triggering value-changed of browse-13. on my value-changed on browse-13, the beginning of the code was to get current browse-13. since it was focused on the blank row, it resulted in an error with no query being found. sorry if i did not include the syntax get current in my first example.

How to get image files from subdirectories within a directory

In matlab i want to access all the images of the extension ".hdr" from subdirectories which in turn are in a directory. And consequently all the image-names must be returned in a cell with one row and many columns, depending upon the number of images.I already used 'getAllFile' but I couldn't get the desired results. Please help me with any other idea. Thank you :-)
Depending on the context, you have a few options. If this program is interacting with a user try this:
[filelist path] = uigetfile('.hdr', 'MultiSelect', 'on')
for ii =1:numel(filelist)
filedir = fullfile(path, filelist{ii};
% Do whatever you want with each file here.
end
In the case above, filelist is the cell array you mentioned in your question. If this isn't what you need, let me know, and I'll add another option.

Problems with empty table view

im trying to write an app that will display a list off lines from a book e.g line 1, line 2 in a table view and you can then select a line to view the corrosponding text.
I've got to the stage where the text should at least appear in the table view(not as far as being able to select it), yet it remains empty.
I used the debugger and was able to find out that there are zero objects in the array used to determine the 'numberOfRowsInSection' and being as this returns zero I think this may explain the problem?
I have pasted up all my code and would really appreciate it if someone has time to skim through it. I know its a big thing to ask but I cant seem to pin point the problem myself.
RootViewController.h --> http://pastie.org/858561
RootViewController.m---> http://pastie.org/858562
BookTestAppDelegate.h ---> http://pastie.org/858566
BookTestAppDelegate.m---> http://pastie.org/858567
LineClass.h----> http://pastie.org/858568
LineClass.m ----> http://pastie.org/858570
SOURCE : http://uploading.com/files/9f5f1249/BookTest.zip/
Thanks guys,
Your sample sqlite database doesn't have table named "animals". But it has table "book". I think you should correct your readLinesFromDatabase method with following SQL statement: select * from book. ;-)