Code for copy data within a range to notepad - excel

I don't understand coding, I've tried but it just doesn't make sense to me. Much respect to all who can learn and understand this complex other language. If any of you can help, I'd be grateful.
I suspect this is a simple problem to solve...
I have a range of cells, A1:E30, in cells in columns B and C within this range data is entered using drop down lists, when certain data is entered into these cells information is automatically entered into columns A and E on the same row. Not all cells within the range will contain data.
What I'd like is a command button that when pressed will copy only the cells within this range that contain text and then paste that text into notepad, without any blank lines and keeping corresponding cells next to each other.
I can do the very basic:
Range("A1:E30").Copy
Shell"notepad.exe",VbNormalFocus
Sendkeys"^V"
The code copies the entire range, but this includes empty lines.
Is there a way to do what I need?
Any help would be most appreciated.

If the lines that are empty are within the data block, you can sort prior to copying. If the blank lines are at the end, you can find the last row of data prior to copying and only copy the data.
LastRow=Cells(Rows.Count,1).End(xlup).Row
Range("A1:E" & LastRow).Copy

Related

How can I copy paste the cell number-formatting, without its contents, from one range to another in excel?

I've an excel sheet exported by an accounts program ('tally' btw) which exported a column of numerical values, which have either 'cr' or 'dr' cell number formatting applied to them. Now I want that 'cr' or 'dr' to be separated into another column, not as formatting, but actual text.
Since, in the source cells, this is made visible by cell formatting dialouge (Ctrl+1), the 'cr/dr' don't actually exist in the source cells and thus can't be copied to target cell range. And consequently won't accept any conditional formatting based on dr or cr values (something I need).
Although, I can copy paste the formatting alone to the target cells range, but that necessitates that I fill some number in target cell (e.g. zero), only then that 'cr/dr' becomes visible. And that's a problem.
Thank you very much.
(I already googled much on this, but couldn't find any solution at all).
2. I can try suggested VBA code, if no other method is available.

How to make an INDIRECT formula but with adjusting ranges

I'm hoping someone can help me make better use of the INDIRECT formula.
I have a list of sheet names in a table and an INDIRECT formula that uses that list to return a value in a specified cell - the list of sheet names is just an easier way for me to drag the formula down the table and read the appropriate cells without having to manually link each sheet.
=INDIRECT("'"&A2&"'!"&"K10")
This works fine for single cells as the range ref is simply stated as the text in the formula (K10), the problem arises when I need to start referring to a range such as K10:K15 and summing the values.
The range K10:K15 will inevitably have new rows added or deleted on the relative tab and as INDIRECT is using text as the reference it means the range doesn't automatically adjust - this is as I understand it one of the 'benefits' of INDIRECT but in this case is actually holding me back.
Also worth noting that the range (K10:K15) may move as rows are added/deleted above this, as this range is part of a larger table.
In simplistic terms I want to achieve the same result as a standard reference to a range on another sheet, e.g. =sum(sheet1!K10:K15) (as this will adjust when rows are added/deleted) but I just want to be able to dictate which sheet is referred to via a list I have in a table on a summary sheet.
How do I either write INDIRECT so the range adjusts when new rows are added/deleted or is there a different formula I should be using that achieves this?
Any advice greatly appreciated :)
=INDIRECT("'"&A2&"'!K"& MATCH(TRUE,INDIRECT("'"&A2&"'!K:K")<>"",0)&":K"&MAX((INDIRECT("'"&A2&"'!K:K")<>"")*(ROW(INDIRECT("'"&A2&"'!K:K")))))
This indirectly references the rows from the first non empty cell up to the last non empty cell in given sheet in column K. Not sure if you need to enter with ctrl + shift + enter (not in the app version).
Note: If the range contains empty cells in between the first and last non empty cell it will be included as value 0
Or in office 365 use the following:
=FILTER(INDIRECT("'"&A2&"'!K:K"),INDIRECT("'"&A2&"'!K:K")<>"")

VBA code to do loop of transposing multiple data from single column

I have thousands of data in a single column and I want to transpose these to a different sheet, I have added a number for each type of data in the column, it looks like this
so I want the code to copy and paste as transposed to another sheet then start again to the next row after 0.
Any help is greatly appreciated thanks in advance.....
I would make a "for each" loop and test for each line the type's number of the information. Then following the number copy and paste it in the right sheet. To know on which line you need to paste, you can have a long variable in each sheet to increment for each paste. Or you can use ".End(xlUp).Row" to know the last cell of the column.

Getting data to input into a spreadsheet by clicking on a button

I'm struggling to get my Excel spreadsheet (2010) to do what I want, but I'm not sure its possible!
What I have is diagrams with numbers (with the numbers in circles) on sheet two, on sheet one I have VLOOKUPs waiting to input the appropriate data. What I want, is for the user to click on the circle containing whichever number, then for that number to be put in the first column of the sheet, thus causing the VLOOKUP to fill in the rest of the data. Any ideas? I'm trying to play about with macros but I've had no luck so far.
Any help would be greatly appreciated
Jazz
EDIT: I've managed to get a macro to copy and paste the data to the correct column, what I now need is for the macro to put the pasted data into the next blank cell in the column
What if you try a command like the following:
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
After you have unlocked the worksheet and copied the data, have the VB code go to the active sheet, and paste your data in row that follows the last used row in the worksheet. If you can weave something like this in, you will be able to avoid indexing the rows with a number. You will also be able to deal with the case that there are empty rows sprinkled within column A in this case.

Automatically insert a new row with merged cells above a cell with formula

I am creating a spreadsheet for use inside our court system. I would like the sheet to automatically expand as it is being filled in. There is no way to pre-determine how many rows will be used. I want new rows to be automatically added when the user fills in all the pre designated rows. That I can do easily.
I already have the VBA automatically creates the new row where I need it.
My problem is the new rows are not formatted the way I need them to be. In my worksheet, in the rows that are added, columns B,C & D need to be merged and columns E & F need to be merged.
How can I add that function to my existing VBA code?
By converting the range into a list, most of this is automatically done. Zero programming. Just read the manual :-)
And by the way, avoid merged cells at any price ! Same effect can be achieved by formatting (center across selection), and avoids plenty of annoyances for range selection, inserting columns, autofill, etc...

Resources