Having difficulty pasting values only from {copy(destination).range.end.offset} - copy

I have tried every combination of paste special and can't figure this one out. I just want to copy the entire row's values, then paste them onto the next sheet. I am extremely close to being finished here, but a few of the cells I loop through have formulas that produce the values and I keep ending up with the lovely "REF" text in my cells.
Dim bottomL As Integer
bottomL = Sheets("Final Body Assembly List").Range("B" & Rows.Count).End(xlUp).Row
Dim c As Range
For Each c In Sheets("Final Body Assembly List").Range("B1:B" & bottomL)
If c.Value >= 1 Then
c.EntireRow.Copy Worksheets("Summary").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next c
End Sub

Related

Table fields digit change when replacing data of different types

Based on this post (Table fields in format in PDF report generator - Matlab), I run the script on a table. In the script, I extract one column, run the function on it, and replace the old column with this new one in identical but copied table (of the original). Strangely, I get that the modified column data is not stored correctly in the new table. Why? I suspect that is it is because of the categorical. How can I fix it?
Code:
clc;
clear all;
dataInput = webread('https://people.sc.fsu.edu/~jburkardt/data/csv/hw_25000.csv');
tempCol = (f(table2array(dataInput(:,2))));
newDataInput = dataInput;
newDataInput(:,2) = table(tempCol);
function FivDigsStr = f(x)
%formatting to character array with 5 significant digits and then splitting.
%at each tab. categorical is needed to remove ' 's that appear around char
%in the output PDF file with newer MATLAB versions
%e.g. with R2018a, there are no ' ' in the output file but ' ' appears with R2020a
FivDigsStr = categorical(split(sprintf('%0.5G\t',x)));
%Removing the last (<undefined>) value (which is included due to \t)
FivDigsStr = FivDigsStr(1:end-1);
end
You cannot replace values of one type with values of some other type. Instead, just rewrite the column. i.e use:
newDataInput.(newDataInput.Properties.VariableNames{2}) = tempCol;
instead of:
newDataInput(:,2) = table(tempCol);

Update multiple source links for pictures in WORD 2016 via VBA

I worked on some VBA code to change all the sourcelocation of all the images. However it is detecting only 3 InlineShapes. There are many more. I inserted all images as Insert and LInk
Sub ChangesSource()
Dim i As Long
Documents("Document.docx").Activate
Debug.Print ActiveDocument.Name
With ActiveDocument
For i = 1 To .InlineShapes.Count
With .InlineShapes(i)
'.shp.LinkFormat.SourceFullName =
.LinkFormat.SourceFullName = Replace(.LinkFormat.SourceFullName, "C:\oldLink", "C:\newLink")
Debug.Print .LinkFormat.SourceFullName
'Debug.Print InlineShapes(i).SourceFullName
End With
Next i
End With
End Sub
Try:
Sub ChangeSource()
Dim i As Long
With ActiveDocument
For i = .InlineShapes.Count To 1 Step -1
With .InlineShapes(i)
If Not .LinkFormat Is Nothing Then
With .LinkFormat
.SourceFullName = Replace(.SourceFullName, .SourcePath, "C:\NewPath\")
End With
End If
End With
Next i
End With
End Sub
If you save the document in the older .doc format, pressing Alt-F9 will expose the INCLUDEPICTURE fields containing the links. You can then use Find/Replace to update the paths (note the use of \\ for the path separators). Pressing Alt-F9, then Ctrl-Shift-F9 will refresh the linked images. You can then re-save the document in the docx format, if you wish. The other option is to use a macro.

How to read a number from text file via Matlab

I have 1000 text files and want to read a number from each file.
format of text file as:
af;laskjdf;lkasjda123241234123
$sakdfja;lskfj12352135qadsfasfa
falskdfjqwr1351
##alskgja;lksjgklajs23523,
asdfa#####1217653asl123654fjaksj
asdkjf23s#q23asjfklj
asko3
I need to read the number ("1217653") behind "#####" in each txt file.
The number will follow the "#####" closely in all text file.
"#####" and the close following number just appear one time in each file.
clc
clear
MyFolderInfo = dir('yourpath/folder');
fidin = fopen(file_name,'r','n','utf-8');
while ~feof(fidin)
tline=fgetl(fidin);
disp(tline)
end
fclose(fidin);
It is not finish yet. I am stuck with the problem that it can not read after the space line.
This is another approach using the function regex. This will easily provide a more advanced way of reading files and does not require reading the full file in one go. The difference from the already given example is basically that I read the file line-by-line, but since the example use this approach I believe it is worth answering. This will return all occurences of "#####NUMBER"
function test()
h = fopen('myfile.txt');
str = fgetl(h);
k = 1;
while (isempty(str) | str ~= -1 ) % Empty line returns empty string and EOF returns -1
res{k} = regexp(str,'#####\d+','match');
k = k+1;
str = fgetl(h);
end
for k=1:length(res)
disp(res{k});
end
EDIT
Using the expression '#####(\d+)' and the argument 'tokens' instead of 'match' Will actually return the digits after the "#####" as a string. The intent with this post was also, apart from showing another way to read the file, to show how to use regexp with a simple example. Both alternatives can be used with suitable conversion.
Assuming the following:
All files are ASCII files.
The number you are looking to extract is directly following #####.
The number you are looking for is a natural number.
##### followed by a number only occurs once per file.
You can use this code snippet inside a for loop to extract each number:
regx='#####(\d+)';
str=fileread(fileName);
num=str2double(regexp(str,regx,'tokens','once'));
Example of for loop
This code will iterate through ALL files in yourpath/folder and save the numbers into num.
regx='#####(\d+)'; % Create regex
folderDir='yourpath/folder';
files=cellstr(ls(folderDir)); % Find all files in folderDir
files=files(3:end); % remove . and ..
num=zeros(1,length(files)); % Pre allocate
for i=1:length(files) % Iterate through files
str=fileread(fullfile(folderDir,files{i})); % Extract str from file
num(i)=str2double(regexp(str,regx,'tokens','once')); % extract number using regex
end
If you want to extract more ''advanced'' numbers e.g. Integers or Real numbers, or handle several occurrences of #####NUMBER in a file you will need to update your question with a better representation of your text files.

How to avoid the repeated paragraghs of long txt files being ignored for importdata in matlab

I am trying to import all double from a txt file, which has this form
#25x1 string
#9999x2 double
.
.
.
#(repeat ten times)
However, when I am trying to use import Wizard, only the first
25x1 string
9999x2 double.
was successfully loaded, the other 9 were simply ignored
How may I import all the data? (Does importdata has a maximum length or something?)
Thanks
It's nothing to do with maximum length, importdata is just not set up for the sort of data file you describe. From the help file:
For ASCII files and spreadsheets, importdata expects
to find numeric data in a rectangular form (that is, like a matrix).
Text headers can appear above or to the left of the numeric data,
as follows:
Column headers or file description text at the top of the file, above
the numeric data. Row headers to the left of the numeric data.
So what is happening is that the first section of your file, which does match the format importdata expects, is being read, and the rest ignored. Instead of importdata, you'll need to use textscan, in particular, this style:
C = textscan(fileID,formatSpec,N)
fileID is returned from fopen. formatspec tells textscan what to expect, and N how many times to repeat it. As long as fileID remains open, repeated calls to textscan continue to read the file from wherever the last read action stopped - rather than going back to the start of the file. So we can do this:
fileID = fopen('myfile.txt');
repeats = 10;
for n = 1:repeats
% read one string, 25 times
C{n,1} = textscan(fileID,'%s',25);
% read two floats, 9999 times
C{n,2} = textscan(fileID,'%f %f',9999);
end
You can then extract your numerical data out of the cell array (if you need it in one block you may want to try using 'CollectOutput',1 as an option).

Mailmerge in Word from xls file with rows with cells that have comma seperated values

I'm an absolute novice at this, but I've got an Excel'02 file with Cells in rows that have comma seperated values which I need for word mailmerge to split and add to newly inserted rows.
Now I've done this in Excel:
Sub tst()
Dim X As Variant
X = Split(Range("A1").Value, ",")
Range("A1").Resize(UBound(X) - LBound(X) + 1).Value = Application.Transpose(X)
End Sub
How do I get Word to do just the same. Please?
Also please include the type of sub I should be using and how to reference anything like tables, cells, ranges etc
Why not just do it in Excel to a scratch worksheet and then merge the data from there?